This is type-script(java-script) array like slice for GoLang
go get -u github.com/poteto-go/tslice@latest
array := []int{0, 1, -1, 2}
filtered := tslice.Filter(array, func(data int) bool {
return data >= 0
})
// => filtered = []int{0, 1, 2}
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
-
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 withOrdered
.
-
Splice
-
ToLocalString
-
ToReversed
-
ToSorted
ToSorted
w/ handler (which return int)ToSortedO
w/o handler. You can use withOrdered
.
-
ToSpliced
-
ToString
-
UnShift
-
Values
-
With
ok github.com/poteto-go/tslice (cached) coverage: 98.7% of statements