2022-11-25 18:19:33 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022 tursom. All rights reserved.
|
|
|
|
* Use of this source code is governed by a GPL-3
|
|
|
|
* license that can be found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2022-03-21 11:02:41 +08:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tursom/GoCollections/collections"
|
|
|
|
"github.com/tursom/GoCollections/exceptions"
|
|
|
|
"github.com/tursom/GoCollections/lang"
|
|
|
|
)
|
|
|
|
|
|
|
|
func AsList[T lang.Object](arr []T) collections.List[T] {
|
2022-04-02 15:25:35 +08:00
|
|
|
return &arrayList[T]{array: arr}
|
2022-03-21 11:02:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func CheckedGet[T any](array []T, index int) (T, exceptions.Exception) {
|
|
|
|
return exceptions.CatchIndexOutOfBound(func() T {
|
|
|
|
return array[index]
|
2022-04-02 15:25:35 +08:00
|
|
|
}, exceptions.Cfg().AddSkipStack(3))
|
2022-03-21 11:02:41 +08:00
|
|
|
}
|