Documentation ¶
Index ¶
- Variables
- func Chain[T any](its ...Nexter[T]) *chainIt[T]
- func FilterMap[T, U any, It Nexter[T]](it It, mapFunc mapFunc[T, U]) *mappedIt[T, U, It]
- func FlatFilterMap[T, U any, It1 Nexter[T], It2 Nexter[It1]](it2 It2, mapFunc mapFunc[T, U]) *flatMappedIt[T, U, It1, It2]
- func One[T any, It Nexter[T]](it It) tipe.Result[T]
- func Slice[T any](data ...T) *sliceIt[T]
- func Sorted[T any, It Nexter[T]](it It, cmpFunc cmpFunc[T], reversed bool) *sortedIt[T, It]
- func SortedKeyFunc[T any, It Nexter[T], K cmp.Ordered](it It, keyFunc func(T) K, reversed bool) *sortedIt[T, It]
- func Stopped[T any](r tipe.Result[T]) bool
- type Ator
- type Nexter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmpty = errors.New("iterator has length == 0") ErrTooMany = errors.New("iterator has length >= 2") )
View Source
var Stop = error(stop{})
Functions ¶
func FlatFilterMap ¶
func FlatFilterMap[T, U any, It1 Nexter[T], It2 Nexter[It1]](it2 It2, mapFunc mapFunc[T, U]) *flatMappedIt[T, U, It1, It2]
Example ¶
package main import ( "fmt" "github.com/hsfzxjy/imbed/util/iter" "github.com/hsfzxjy/tipe" ) func Collect[T any](it iter.Ator[T]) []T { var res []T for it.HasNext() { res = append(res, it.Next().Unwrap()) } return res } func main() { its := []iter.Nexter[int]{ iter.Slice(1, 2, 3), iter.Slice(4, 5, 6), iter.Slice[int](), } flatten := iter.FlatFilterMap(iter.Slice(its...), tipe.Ok[int]) fmt.Printf("%v\n", Collect(flatten)) chain := iter.Chain(iter.Slice(1, 2, 3), iter.Slice(4, 5, 6)) fmt.Printf("%v\n", Collect(chain)) }
Output: [1 2 3 4 5 6] [1 2 3 4 5 6]
func Sorted ¶
Example ¶
package main import ( "cmp" "fmt" "github.com/hsfzxjy/imbed/util/iter" ) func Collect[T any](it iter.Ator[T]) []T { var res []T for it.HasNext() { res = append(res, it.Next().Unwrap()) } return res } func main() { it := iter.Sorted(iter.Slice(2, 4, 6, 5, 3, 1), cmp.Compare[int], false) fmt.Printf("%v\n", Collect(it)) }
Output: [1 2 3 4 5 6]
func SortedKeyFunc ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.