Skip to content

poteto-go/tslice

Repository files navigation

tslice

This is type-script(java-script) array like slice for GoLang

go get -u github.com/poteto-go/tslice@latest

Examples

Filter

array := []int{0, 1, -1, 2}
filtered := tslice.Filter(array, func(data int) bool {
	return data >= 0
})
// => filtered = []int{0, 1, 2}

Reduce

type User struct {
	city string
	age  int
}

users := []User{
	{"Kawasaki", 10}, {"Yokohama", 11}, {"Kawasaki", 22},
}

result := tslice.Reduce(users, func(acc int, cur User) int {
	if cur.city == "Kawasaki" {
		return acc + cur.age
	}
	
	return acc + 0
})
// => 32

Func

  • At
  • Concat
  • CopyWithin
  • Entries
  • Every
  • Fill
  • Filter
  • Find: return (0 value, false) if not found
  • FindIndex
  • FindLast: return (0 value, false) if not found
  • FindLastIndex
  • Flat
  • FlatMap
  • ForEach
  • Includes
  • IndexOf
  • Join
  • Keys
  • LastIndexOf
  • Map
  • Pop
  • Push
  • Reduce
  • ReduceRight
  • Reverse
  • Shift
  • Slice
  • Some
  • Sort
    • Sort w/ handler (which return int)
    • SortO w/o handler. You can use with Ordered.
  • Splice
  • ToLocalString
  • ToReversed
  • ToSorted
    • ToSorted w/ handler (which return int)
    • ToSortedO w/o handler. You can use with Ordered.
  • ToSpliced
  • ToString
  • UnShift
  • Values
  • With

Latest test coverage (2025/02/12)

ok github.com/poteto-go/tslice (cached) coverage: 98.7% of statements