 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶ added in v0.198.0
func Clone[T any](src []T) []T
Clone creates a clone from passed src slice.
Example ¶
package main
import (
	"go.llib.dev/frameless/pkg/slicekit"
)
func main() {
	var (
		src = []string{"a", "b", "c"}
		dst = slicekit.Clone(src)
	)
	_, _ = src, dst
}
func Lookup ¶ added in v0.186.0
Example ¶
package main
import (
	"go.llib.dev/frameless/pkg/slicekit"
)
func main() {
	vs := []int{2, 4, 8, 16}
	slicekit.Lookup(vs, 0)      // -> return 2, true
	slicekit.Lookup(vs, 0-1)    // lookup previous -> return 0, false
	slicekit.Lookup(vs, 0+1)    // lookup next -> return 4, true
	slicekit.Lookup(vs, 0+1000) // lookup 1000th element -> return 0, false
}
func Map ¶
Map will do a mapping from an input type into an output type.
Example ¶
package main
import (
	"go.llib.dev/frameless/pkg/slicekit"
	"strconv"
	"strings"
)
func main() {
	var x = []string{"a", "b", "c"}
	_ = slicekit.Must(slicekit.Map[string](x, strings.ToUpper)) // []string{"A", "B", "C"}
	var ns = []string{"1", "2", "3"}
	_, err := slicekit.Map[int](ns, strconv.Atoi) // []int{1, 2, 3}
	if err != nil {
		panic(err)
	}
}
func Merge ¶ added in v0.188.0
func Merge[T any](slices ...[]T) []T
Merge will merge every []T slice into a single one.
Example ¶
package main
import (
	"go.llib.dev/frameless/pkg/slicekit"
)
func main() {
	var (
		a   = []string{"a", "b", "c"}
		b   = []string{"1", "2", "3"}
		c   = []string{"1", "B", "3"}
		out = slicekit.Merge(a, b, c)
	)
	_ = out // []string{"a", "b", "c", "1", "2", "3", "1", "B", "3"}
}
func Must ¶
Example ¶
package main
import (
	"fmt"
	"go.llib.dev/frameless/pkg/slicekit"
)
func main() {
	var x = []int{1, 2, 3}
	x = slicekit.Must(slicekit.Map[int](x, func(v int) int {
		return v * 2
	}))
	v := slicekit.Must(slicekit.Reduce[int](x, 42, func(output int, current int) int {
		return output + current
	}))
	fmt.Println("result:", v)
}
func Reduce ¶
Reduce iterates over a slice, combining elements using the reducer function.
Example ¶
package main
import (
	"fmt"
	"go.llib.dev/frameless/pkg/slicekit"
)
func main() {
	var x = []string{"a", "b", "c"}
	got, err := slicekit.Reduce[string](x, "|", func(o string, i string) string {
		return o + i
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(got) // "|abc"
}
Types ¶
This section is empty.
 Click to show internal directories. 
   Click to hide internal directories.