Have you ever wanted to have some handy methods that can operate on any of the collections types in go? here is the solution.
Index(<Tslice>, <val>)
where Tslice is a slice of typeT
. Returns an Int which is the index of valInclude(<Tslice>, <val>)
where Tslice is a slice of typeT
. Returns a BooleanIsConsecutive(<Tslice>)
where Tslice is a slice of typeT
. Returns a Booleantrue
if elements in slice are consecutiveCompare(<Tslice1>, <Tslice2>, <func>)
where Tslice1, Tslice2 are slices of typeT
andfunc
a function to compare individual elements of the slices. Returns a BooleanMap(<Tslice>, <func>)
where Tslice is a slice of typeT
and func a function.Returns T appliesfunc
to each item in the slice.Filter(<Tslice>, <func>)
where Tslice is a slice of typeT
andfunc
a function that has an expression . Returns a slice of type TAll(<Tslice>, <func>)
Returns a Boolean.true
if all elements in slice are notfalsey
i.e 0 or NullAny(<Tslice>, <func>)
Returns a Boolean.true
if atleast 1 element in slice the is nottruthy
package main
import (
"fmt"
"github.com/ertush/collectibles"
)
func square(b byte) byte {
return b * b
}
func main() {
var b *collectibles.Byt
bs := []byte{1, 3, 5, 6, 7, 9}
sq := b.Map(bs, square)
fmt.Printf("\n\n%v, %v\n\n", sq, b.Include(sq, 36)) // [1 9 25 36 49 81], true
}