github.com/tursom/GoCollections@v0.3.10/util/Arrays.go (about) 1 /* 2 * Copyright (c) 2022 tursom. All rights reserved. 3 * Use of this source code is governed by a GPL-3 4 * license that can be found in the LICENSE file. 5 */ 6 7 package util 8 9 import ( 10 "github.com/tursom/GoCollections/collections" 11 "github.com/tursom/GoCollections/exceptions" 12 "github.com/tursom/GoCollections/lang" 13 ) 14 15 func AsList[T lang.Object](arr []T) collections.List[T] { 16 return &arrayList[T]{array: arr} 17 } 18 19 func CheckedGet[T any](array []T, index int) (T, exceptions.Exception) { 20 return exceptions.CatchIndexOutOfBound(func() T { 21 return array[index] 22 }, exceptions.Cfg().AddSkipStack(3)) 23 }