Documentation
¶
Index ¶
- func Append[E any](seq iter.Seq[E], elems ...E) iter.Seq[E]
- func Chunk[E any](seq iter.Seq[E], size int) iter.Seq[iter.Seq[E]]
- func Collect[E any](seq iter.Seq[E]) []E
- func Concat[E any](sequences ...iter.Seq[E]) iter.Seq[E]
- func Contains[E comparable](seq iter.Seq[E], elem E) bool
- func ContainsAll[E comparable](seq iter.Seq[E], elements ...E) bool
- func Count[E any](seq iter.Seq[E]) int
- func Cycle[E any](seq iter.Seq[E], count int) iter.Seq[E]
- func Distinct[E comparable](seq iter.Seq[E]) iter.Seq[E]
- func Each[E any](seq iter.Seq[E], consumer Consumer[E]) iter.Seq[E]
- func Every[E any](seq iter.Seq[E], predicate Predicate[E]) bool
- func Exists[E any](seq iter.Seq[E], predicate Predicate[E]) bool
- func Filter[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func Find[E any](seq iter.Seq[E], predicate Predicate[E]) optional.Elem[E]
- func FindAll[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func FindLast[E any](seq iter.Seq[E], predicate Predicate[E]) optional.Elem[E]
- func FlatMap[E any, R any](seq iter.Seq[E], mapper Mapper[E, iter.Seq[R]]) iter.Seq[R]
- func Flatten[Seq iter.Seq[iter.Seq[E]], E any](seq Seq) iter.Seq[E]
- func Flush[E any](seq iter.Seq[E])
- func Fold[E any](seq iter.Seq[E], accumulator func(agg E, item E) E) optional.Elem[E]
- func FoldRight[E any](seq iter.Seq[E], accumulator func(agg E, item E) E) optional.Elem[E]
- func ForEach[E any](seq iter.Seq[E], consumer Consumer[E])
- func FromSlice[Slice ~[]E, E any](slice Slice) iter.Seq[E]
- func GroupBy[E any, K comparable](seq iter.Seq[E], by Mapper[E, K]) iter.Seq2[K, iter.Seq[E]]
- func IsEmpty[E any](seq iter.Seq[E]) bool
- func IsNotEmpty[E any](seq iter.Seq[E]) bool
- func Limit[E any](seq iter.Seq[E], n int) iter.Seq[E]
- func Map[E any, R any](seq iter.Seq[E], mapper Mapper[E, R]) iter.Seq[R]
- func Max[E types.Ordered](seq iter.Seq[E]) optional.Elem[E]
- func Min[E types.Ordered](seq iter.Seq[E]) optional.Elem[E]
- func None[E any](seq iter.Seq[E], predicate Predicate[E]) bool
- func NotContains[E comparable](seq iter.Seq[E], elem E) bool
- func Of[E any](elems ...E) iter.Seq[E]
- func Offset[E any](seq iter.Seq[E], n int) iter.Seq[E]
- func Partition[E any](seq iter.Seq[E], size int) iter.Seq[iter.Seq[E]]
- func PartitionBy[E any, K comparable](seq iter.Seq[E], by Mapper[E, K]) iter.Seq[iter.Seq[E]]
- func Prepend[E any](seq iter.Seq[E], elems ...E) iter.Seq[E]
- func Range[E types.Integer](start, end E) iter.Seq[E]
- func RangeTo[E types.Integer](end E) iter.Seq[E]
- func RangeWithStep[E types.Integer](start, end, step E) iter.Seq[E]
- func Reduce[E any, R any](seq iter.Seq[E], accumulator func(agg R, item E) R, initial R) R
- func ReduceRight[E any, R any](seq iter.Seq[E], accumulator func(agg R, item E) R, initial R) R
- func Repeat[E any](elem E, count int) iter.Seq[E]
- func Reverse[E any](seq iter.Seq[E]) iter.Seq[E]
- func Select[E any, R any](seq iter.Seq[E], mapper Mapper[E, R]) iter.Seq[R]
- func Skip[E any](seq iter.Seq[E], n int) iter.Seq[E]
- func SkipUntil[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func SkipWhile[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func Sort[E types.Ordered](seq iter.Seq[E]) iter.Seq[E]
- func SortBy[E any, K types.Ordered](seq iter.Seq[E], keyFn Mapper[E, K]) iter.Seq[E]
- func SortComparing[E any](seq iter.Seq[E], cmp func(a, b E) int) iter.Seq[E]
- func Take[E any](seq iter.Seq[E], n int) iter.Seq[E]
- func TakeUntil[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func TakeWhile[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func Tap[E any](seq iter.Seq[E], consumer func(E)) iter.Seq[E]
- func Tick(d time.Duration) iter.Seq[time.Time]
- func ToSlice[Slice ~[]E, E any](seq iter.Seq[E], slice Slice) Slice
- func Union[E types.Comparable](seq1 iter.Seq[E], seq2 iter.Seq[E]) iter.Seq[E]
- func UnionAll[E any](seq1 iter.Seq[E], seq2 iter.Seq[E]) iter.Seq[E]
- func Uniq[E comparable](seq iter.Seq[E]) iter.Seq[E]
- func UniqBy[E any, K comparable](seq iter.Seq[E], mapper Mapper[E, K]) iter.Seq[E]
- func Where[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]
- func Zip[E any, R any](seq1 iter.Seq[E], seq2 iter.Seq[R]) iter.Seq2[E, R]
- type Consumer
- type Mapper
- type Predicate
- type Sequence
- func (s Sequence[E]) Append(elems ...E) Sequence[E]
- func (s Sequence[E]) Collect() []E
- func (s Sequence[E]) Contains(elem E) bool
- func (s Sequence[E]) ContainsAll(elements ...E) bool
- func (s Sequence[E]) Count() int
- func (s Sequence[E]) Distinct() Sequence[E]
- func (s Sequence[E]) Each(consumer Consumer[E]) Sequence[E]
- func (s Sequence[E]) Every(predicate Predicate[E]) bool
- func (s Sequence[E]) Exists(predicate Predicate[E]) bool
- func (s Sequence[E]) Filter(predicate Predicate[E]) Sequence[E]
- func (s Sequence[E]) Find(predicate Predicate[E]) optional.Elem[E]
- func (s Sequence[E]) FindAll(predicate Predicate[E]) Sequence[E]
- func (s Sequence[E]) FindLast(predicate Predicate[E]) optional.Elem[E]
- func (s Sequence[E]) Flush()
- func (s Sequence[E]) Fold(accumulator func(agg E, item E) E) optional.Elem[E]
- func (s Sequence[E]) FoldRight(accumulator func(agg E, item E) E) optional.Elem[E]
- func (s Sequence[E]) ForEach(consumer Consumer[E])
- func (s Sequence[E]) IsEmpty() bool
- func (s Sequence[E]) IsNotEmpty() bool
- func (s Sequence[E]) Limit(n int) Sequence[E]
- func (s Sequence[E]) None(predicate Predicate[E]) bool
- func (s Sequence[E]) NotContains(elem E) bool
- func (s Sequence[E]) Offset(n int) Sequence[E]
- func (s Sequence[E]) Partition(size int) iter.Seq[iter.Seq[E]]
- func (s Sequence[E]) Prepend(elems ...E) Sequence[E]
- func (s Sequence[E]) Repeat(count int) Sequence[E]
- func (s Sequence[E]) Reverse() Sequence[E]
- func (s Sequence[E]) Skip(n int) Sequence[E]
- func (s Sequence[E]) Take(n int) Sequence[E]
- func (s Sequence[E]) Tap(consumer func(E)) Sequence[E]
- func (s Sequence[E]) ToSlice(slice []E) []E
- func (s Sequence[E]) Union(other Sequence[E]) Sequence[E]
- func (s Sequence[E]) UnionAll(other Sequence[E]) Sequence[E]
- func (s Sequence[E]) Uniq() Sequence[E]
- func (s Sequence[E]) Where(predicate Predicate[E]) Sequence[E]
Examples ¶
- Append
- AsSequence
- Chunk
- Collect
- Concat
- ConcatSequences
- Contains
- ContainsAll
- Cycle
- Distinct
- Each
- Every
- Exists
- Filter
- Find
- FindAll
- FindLast
- FlatMap
- Flatten
- Fold
- FoldRight
- ForEach
- FromSlice
- GroupBy
- IsEmpty
- IsNotEmpty
- Limit
- Map
- Max
- Min
- None
- NotContains
- Of
- Offset
- Partition
- PartitionBy
- Prepend
- Range
- RangeTo
- RangeWithStep
- Reduce
- ReduceRight
- Repeat
- Reverse
- Select
- Sequence.Append
- Sequence.Collect
- Sequence.Contains
- Sequence.ContainsAll
- Sequence.Count
- Sequence.Distinct
- Sequence.Each
- Sequence.Every
- Sequence.Exists
- Sequence.Filter
- Sequence.Find
- Sequence.FindAll
- Sequence.FindLast
- Sequence.Flush
- Sequence.Fold
- Sequence.FoldRight
- Sequence.ForEach
- Sequence.IsEmpty
- Sequence.IsNotEmpty
- Sequence.Limit
- Sequence.None
- Sequence.NotContains
- Sequence.Offset
- Sequence.Partition
- Sequence.Prepend
- Sequence.Repeat
- Sequence.Reverse
- Sequence.Skip
- Sequence.Take
- Sequence.Tap
- Sequence.ToSlice
- Sequence.Union
- Sequence.UnionAll
- Sequence.Uniq
- Sequence.Where
- Skip
- Sort
- SortBy
- SortComparing
- Take
- TakeWhile
- Tap
- Tick
- ToSlice
- Union
- UnionAll
- Uniq
- UniqBy
- Where
- Zip
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append appends elements to the end of a sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
initial := seq.Of(1, 2, 3)
appended := seq.Append(initial, 4, 5, 6)
result := seq.Collect(appended)
fmt.Println(result)
}
Output: [1 2 3 4 5 6]
func Chunk ¶
Chunk splits the sequence into chunks of the given size.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5, 6)
chunks := seq.Chunk(input, 3)
result := seq.Collect(chunks)
for _, chunk := range result {
fmt.Println(seq.Collect(chunk))
}
}
Output: [1 2 3] [4 5 6]
func Collect ¶
Collect collects the elements of the given sequence into a slice.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.Of(1, 2, 3)
result := seq.Collect(sequence)
fmt.Println(result)
}
Output: [1 2 3]
func Concat ¶
Concat concatenates multiple sequences into a single sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.Of(1, 2, 3)
seq2 := seq.Of(4, 5, 6)
concatenated := seq.Concat(seq1, seq2)
result := seq.Collect(concatenated)
fmt.Println(result)
}
Output: [1 2 3 4 5 6]
func Contains ¶
func Contains[E comparable](seq iter.Seq[E], elem E) bool
Contains returns true if the element is in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
contains := seq.Contains(input, 3)
fmt.Println(contains)
}
Output: true
func ContainsAll ¶
func ContainsAll[E comparable](seq iter.Seq[E], elements ...E) bool
ContainsAll returns true if all elements are in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
containsAll := seq.ContainsAll(input, 2, 3)
fmt.Println(containsAll)
}
Output: true
func Cycle ¶
Cycle repeats the sequence count times.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3)
cycled := seq.Cycle(input, 2)
result := seq.Collect(cycled)
fmt.Println(result)
}
Output: [1 2 3 1 2 3]
func Distinct ¶
func Distinct[E comparable](seq iter.Seq[E]) iter.Seq[E]
Distinct returns a sequence with only unique elements. SQL-like alias for Uniq
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 2, 3, 3, 3)
distinct := seq.Distinct(input)
result := seq.Collect(distinct)
fmt.Println(result)
}
Output: [1 2 3]
func Each ¶
Each is an alias for Tap.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.Each(seq.Of(1, 2, 3), func(v int) {
fmt.Println(v)
})
seq.Flush(sequence)
}
Output: 1 2 3
func Every ¶
Every returns true if all elements satisfy the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(2, 4, 6, 8)
every := seq.Every(input, func(v int) bool { return v%2 == 0 })
fmt.Println(every)
}
Output: true
func Exists ¶
Exists returns true if there is at least one element that satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
exists := seq.Exists(input, func(v int) bool { return v > 4 })
fmt.Println(exists)
}
Output: true
func Filter ¶
Filter returns a new sequence that contains only the elements that satisfy the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
filtered := seq.Filter(input, func(v int) bool {
return v%2 == 0
})
result := seq.Collect(filtered)
fmt.Printf("%v\n", result)
}
Output: [2 4]
func Find ¶
Find returns the first element that satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
found := seq.Find(input, func(v int) bool { return v > 3 })
fmt.Println(found.MustGet())
}
Output: 4
func FindAll ¶
FindAll returns all elements that satisfy the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
found := seq.FindAll(input, func(v int) bool { return v > 3 })
result := seq.Collect(found)
fmt.Println(result)
}
Output: [4 5]
func FindLast ¶
FindLast returns the last element that satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
found := seq.FindLast(input, func(v int) bool { return v > 3 })
fmt.Println(found.MustGet())
}
Output: 5
func FlatMap ¶
FlatMap applies a mapper function to each element of the sequence and flattens the result.
Example ¶
package main
import (
"fmt"
"iter"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(0, 3)
flatMapped := seq.FlatMap(input, func(it int) iter.Seq[int] {
return seq.Of[int](1+it, 2+it, 3+it)
})
result := seq.Collect(flatMapped)
fmt.Println(result)
}
Output: [1 2 3 4 5 6]
func Flatten ¶
Flatten flattens a sequence of sequences.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(seq.Of(1, 2), seq.Of(3, 4))
flattened := seq.Flatten(input)
result := seq.Collect(flattened)
fmt.Println(result)
}
Output: [1 2 3 4]
func Fold ¶
Fold applies a function against an accumulator and each element in the sequence (from left to right) to reduce it to a single value.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of("a", "b", "c")
sum := seq.Fold(input, func(agg, item string) string {
return agg + item
})
fmt.Println(sum.MustGet())
}
Output: abc
func FoldRight ¶
FoldRight applies a function against an accumulator and each element in the sequence (from right to left) to reduce it to a single value.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of("a", "b", "c")
sum := seq.FoldRight(input, func(agg, item string) string {
return agg + item
})
fmt.Println(sum.MustGet())
}
Output: cba
func ForEach ¶
ForEach applies consumer to each element of the input sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq.ForEach(seq.Of(1, 2, 3), func(v int) {
fmt.Println(v)
})
}
Output: 1 2 3
func FromSlice ¶
FromSlice creates a new sequence from the given slice.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
slice := []int{1, 2, 3}
sequence := seq.FromSlice(slice)
result := seq.Collect(sequence)
fmt.Println(result)
}
Output: [1 2 3]
func GroupBy ¶
GroupBy groups the sequence by the given key.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5, 6)
groups := seq.GroupBy(input, func(v int) int {
return v % 2
})
for k, v := range groups {
fmt.Printf("%d: %v\n", k, seq.Collect(v))
}
}
Output: 1: [1 3 5] 0: [2 4 6]
func IsEmpty ¶
IsEmpty returns true if the sequence is empty.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3)
fmt.Println(seq.IsEmpty(input))
}
Output: false
func IsNotEmpty ¶
IsNotEmpty returns true if the sequence is not empty.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3)
isNotEmpty := seq.IsNotEmpty(input)
fmt.Println(isNotEmpty)
}
Output: true
func Limit ¶
Limit returns a new sequence that contains only the first n elements of the given sequence. SQL-like alias for Take
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
limited := seq.Limit(input, 2)
result := seq.Collect(limited)
fmt.Printf("%v\n", result)
}
Output: [1 2]
func Map ¶
Map applies a mapper function to each element of the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3)
mapped := seq.Map(input, func(v int) string {
return fmt.Sprintf("Number_%d", v)
})
result := seq.Collect(mapped)
fmt.Println(result)
}
Output: [Number_1 Number_2 Number_3]
func Max ¶
Max returns the maximum element in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(2, 3, 1, 5, 4)
maxVal := seq.Max(input)
fmt.Println(maxVal.MustGet())
}
Output: 5
func Min ¶
Min returns the minimum element in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(2, 3, 1, 5, 4)
maxVal := seq.Min(input)
fmt.Println(maxVal.MustGet())
}
Output: 1
func None ¶
None returns true if no element satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
none := seq.None(input, func(v int) bool { return v > 5 })
fmt.Println(none)
}
Output: true
func NotContains ¶
func NotContains[E comparable](seq iter.Seq[E], elem E) bool
NotContains returns true if the element is not in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
contains := seq.NotContains(input, 3)
fmt.Println(contains)
}
Output: false
func Of ¶
Of creates a new sequence from the given elements.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.Of(1, 2, 3)
result := seq.Collect(sequence)
fmt.Println(result)
}
Output: [1 2 3]
func Offset ¶
Offset returns a new sequence that skips the first n elements of the given sequence. SQL-like alias for Skip
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
skipped := seq.Offset(input, 2)
result := seq.Collect(skipped)
fmt.Printf("%v\n", result)
}
Output: [3 4 5]
func Partition ¶
Partition splits the sequence into chunks of the given size.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5, 6)
partitions := seq.Partition(input, 2)
result := seq.Collect(partitions)
for _, partition := range result {
fmt.Println(seq.Collect(partition))
}
}
Output: [1 2] [3 4] [5 6]
func PartitionBy ¶
PartitionBy splits the sequence into chunks based on the given key.
Example ¶
package main
import (
"fmt"
"iter"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5, 6)
partitions := seq.PartitionBy(input, func(v int) int {
return v % 2
})
// Notice that the order of the partitions is not guaranteed
sorted := seq.SortBy(partitions, func(p iter.Seq[int]) int {
next, stop := iter.Pull(p)
defer stop()
v, _ := next()
return v
})
for partition := range sorted {
fmt.Println(seq.Collect(partition))
}
}
Output: [1 3 5] [2 4 6]
func Prepend ¶
Prepend prepends elements to the beginning of a sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
initial := seq.Of(4, 5, 6)
prepended := seq.Prepend(initial, 1, 2, 3)
result := seq.Collect(prepended)
fmt.Println(result)
}
Output: [1 2 3 4 5 6]
func Range ¶
Range returns a sequence that yields integers from `start` to `end`.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
ranged := seq.Range(0, 5)
result := seq.Collect(ranged)
fmt.Println(result)
}
Output: [0 1 2 3 4]
func RangeTo ¶
RangeTo returns a sequence that yields integers from 0 to `end`.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
ranged := seq.RangeTo(5)
result := seq.Collect(ranged)
fmt.Println(result)
}
Output: [0 1 2 3 4]
func RangeWithStep ¶
RangeWithStep returns a sequence that yields integers from `start` to `end` with `step`.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
ranged := seq.RangeWithStep(0, 10, 2)
result := seq.Collect(ranged)
fmt.Println(result)
}
Output: [0 2 4 6 8]
func Reduce ¶
Reduce applies a function against an accumulator and each element in the sequence (from left to right) to reduce it to a single value.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of("a", "b", "c")
concat := seq.Reduce(input, func(agg, item string) string {
return agg + item
}, "")
fmt.Println(concat)
}
Output: abc
func ReduceRight ¶
ReduceRight applies a function against an accumulator and each element in the sequence (from right to left) to reduce it to a single value.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of("a", "b", "c")
concat := seq.ReduceRight(input, func(agg, item string) string {
return agg + item
}, "")
fmt.Println(concat)
}
Output: cba
func Repeat ¶
Repeat returns a sequence that yields the same element `count` times.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
repeated := seq.Repeat("hello", 3)
result := seq.Collect(repeated)
fmt.Println(result)
}
Output: [hello hello hello]
func Reverse ¶
Reverse creates a new sequence that iterates over the elements of the given sequence in reverse order.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.Of(1, 2, 3)
reversed := seq.Reverse(sequence)
result := seq.Collect(reversed)
fmt.Println(result)
}
Output: [3 2 1]
func Select ¶
Select applies a mapper function to each element of the sequence. SQL-like alias for Map
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3)
mapped := seq.Select(input, func(v int) string {
return fmt.Sprintf("Number_%d", v)
})
result := seq.Collect(mapped)
fmt.Println(result)
}
Output: [Number_1 Number_2 Number_3]
func Skip ¶
Skip returns a new sequence that skips the first n elements of the given sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
skipped := seq.Skip(input, 2)
result := seq.Collect(skipped)
fmt.Printf("%v\n", result)
}
Output: [3 4 5]
func Sort ¶
Sort sorts the elements of a sequence in ascending order.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
sorted := seq.Sort(input)
result := seq.Collect(sorted)
fmt.Println(result)
}
Output: [1 1 2 3 3 4 5 5 5 6 9]
func SortBy ¶
SortBy sorts the elements of a sequence in ascending order by the key returned by keyFn.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
type Person struct {
Name string
Age int
}
input := seq.Of(
Person{"Alice", 30},
Person{"Bob", 25},
Person{"Charlie", 35},
)
sorted := seq.SortBy(input, func(p Person) int {
return p.Age
})
for p := range sorted {
fmt.Printf("%s (%d)\n", p.Name, p.Age)
}
}
Output: Bob (25) Alice (30) Charlie (35)
func SortComparing ¶
SortComparing sorts the elements of a sequence in ascending order using the cmp function.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
type Person struct {
Name string
Age int
}
input := seq.Of(
Person{"Alice", 30},
Person{"Bob", 25},
Person{"Charlie", 35},
)
sorted := seq.SortComparing(input, func(a, b Person) int {
return a.Age - b.Age
})
for p := range sorted {
fmt.Printf("%s (%d)\n", p.Name, p.Age)
}
}
Output: Bob (25) Alice (30) Charlie (35)
func Take ¶
Take returns a new sequence that contains only the first n elements of the given sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
taken := seq.Take(input, 3)
result := seq.Collect(taken)
fmt.Printf("%v\n", result)
}
Output: [1 2 3]
func TakeUntil ¶
TakeUntil returns a new sequence that contains elements until the predicate is true.
func TakeWhile ¶
TakeWhile returns a new sequence that contains elements while the predicate is true.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 2, 1)
taken := seq.TakeWhile(input, func(v int) bool {
return v < 3
})
result := seq.Collect(taken)
fmt.Printf("%v\n", result)
}
Output: [1 2]
func Tap ¶
Tap returns a sequence that applies the given consumer to each element of the input sequence and pass it further.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.Tap(seq.Of(1, 2, 3), func(v int) {
fmt.Println(v)
})
seq.Flush(sequence)
}
Output: 1 2 3
func Tick ¶
Tick returns a sequence that yields the current time every duration.
Example ¶
package main
import (
"fmt"
"time"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
ticker := seq.Tick(1 * time.Millisecond)
ticker = seq.Take(ticker, 5)
ticker = seq.Tap(ticker, func(v time.Time) {
fmt.Println(v.Format("15:04:05.000"))
})
seq.Flush(ticker)
// Example Output:
// 00:00:00.000
// 00:00:00.001
// 00:00:00.002
// 00:00:00.003
// 00:00:00.004
}
Output:
func ToSlice ¶
ToSlice collects the elements of the given sequence into a slice.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.Of(1, 2, 3)
slice := make([]int, 0, 3)
result := seq.ToSlice(sequence, slice)
fmt.Println(result)
}
Output: [1 2 3]
func Union ¶
Union returns a sequence that contains all distinct elements from both input sequences.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.Of(1, 2, 3)
seq2 := seq.Of(3, 4, 5)
union := seq.Union(seq1, seq2)
result := seq.Collect(union)
fmt.Println(result)
}
Output: [1 2 3 4 5]
func UnionAll ¶
UnionAll returns a sequence that contains all elements from both input sequences.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.Of(1, 2, 3)
seq2 := seq.Of(3, 4, 5)
unionAll := seq.UnionAll(seq1, seq2)
result := seq.Collect(unionAll)
fmt.Println(result)
}
Output: [1 2 3 3 4 5]
func Uniq ¶
func Uniq[E comparable](seq iter.Seq[E]) iter.Seq[E]
Uniq returns a sequence with only unique elements.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 2, 3, 3, 3)
unique := seq.Uniq(input)
result := seq.Collect(unique)
fmt.Println(result)
}
Output: [1 2 3]
func UniqBy ¶
UniqBy returns a sequence with only unique elements based on a key.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of("apple", "banana", "apricot", "blueberry")
uniqueBy := seq.UniqBy(input, func(v string) string {
return v[:1] // unique by first letter
})
result := seq.Collect(uniqueBy)
fmt.Println(result)
}
Output: [apple banana]
func Where ¶
Where returns a new sequence that contains only the elements that satisfy the predicate. SQL-like alias for Filter
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
input := seq.Of(1, 2, 3, 4, 5)
filtered := seq.Where(input, func(v int) bool {
return v%2 == 0
})
result := seq.Collect(filtered)
fmt.Printf("%v\n", result)
}
Output: [2 4]
func Zip ¶
Zip combines two sequences into a iter.Seq2.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.Of(1, 2, 3)
seq2 := seq.Of("a", "b", "c")
zipped := seq.Zip(seq1, seq2)
for k, v := range zipped {
fmt.Printf("%d: %s\n", k, v)
}
}
Output: 1: a 2: b 3: c
Types ¶
type Consumer ¶
type Consumer[E any] = func(E)
Consumer is a function that consumes an element of a sequence.
type Sequence ¶
type Sequence[E comparable] struct { // contains filtered or unexported fields }
Sequence is a monad representing a sequence of elements.
func AsSequence ¶
func AsSequence[E comparable](seq iter.Seq[E]) Sequence[E]
AsSequence wraps an iter.Seq to provide a possibility to pipe several method calls.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
result := sequence.Collect()
fmt.Println(result)
}
Output: [1 2 3]
func ConcatSequences ¶
func ConcatSequences[E comparable](sequences ...Sequence[E]) Sequence[E]
ConcatSequences concatenates multiple sequences into a single sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.AsSequence(seq.Of(1, 2))
seq2 := seq.AsSequence(seq.Of(3, 4))
concatenated := seq.ConcatSequences(seq1, seq2)
result := concatenated.Collect()
fmt.Println(result)
}
Output: [1 2 3 4]
func (Sequence[E]) Append ¶
Append appends elements to the end of a sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
appended := sequence.Append(4, 5)
result := appended.Collect()
fmt.Println(result)
}
Output: [1 2 3 4 5]
func (Sequence[E]) Collect ¶
func (s Sequence[E]) Collect() []E
Collect collects the elements of the sequence into a slice.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
result := sequence.Collect()
fmt.Println(result)
}
Output: [1 2 3]
func (Sequence[E]) Contains ¶
Contains returns true if the element is in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
contains := sequence.Contains(3)
fmt.Println(contains)
}
Output: true
func (Sequence[E]) ContainsAll ¶
ContainsAll returns true if all elements are in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
containsAll := sequence.ContainsAll(2, 3, 4)
fmt.Println(containsAll)
}
Output: true
func (Sequence[E]) Count ¶
Count returns the number of elements in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
count := sequence.Count()
fmt.Println(count)
}
Output: 3
func (Sequence[E]) Distinct ¶
Distinct returns a new sequence with only unique elements. SQL-like alias for Uniq
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 2, 3, 3, 3))
distinct := sequence.Distinct()
result := distinct.Collect()
fmt.Println(result)
}
Output: [1 2 3]
func (Sequence[E]) Each ¶
Each returns a new sequence that calls the consumer for each element of the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3)).Each(func(v int) {
fmt.Println(v)
})
sequence.Flush()
}
Output: 1 2 3
func (Sequence[E]) Every ¶
Every returns true if all elements satisfy the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
every := sequence.Every(func(v int) bool {
return v > 0
})
fmt.Println(every)
}
Output: true
func (Sequence[E]) Exists ¶
Exists returns true if there is at least one element that satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
exists := sequence.Exists(func(v int) bool {
return v > 3
})
fmt.Println(exists)
}
Output: true
func (Sequence[E]) Filter ¶
Filter returns a new sequence with elements that satisfy the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
filtered := sequence.Filter(func(v int) bool {
return v%2 == 0
})
result := filtered.Collect()
fmt.Println(result)
}
Output: [2 4]
func (Sequence[E]) Find ¶
Find returns the first element that satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
found := sequence.Find(func(v int) bool {
return v > 3
})
fmt.Println(found.MustGet())
}
Output: 4
func (Sequence[E]) FindAll ¶
FindAll returns all elements that satisfy the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
foundAll := sequence.FindAll(func(v int) bool {
return v > 3
})
result := foundAll.Collect()
fmt.Println(result)
}
Output: [4 5]
func (Sequence[E]) FindLast ¶
FindLast returns the last element that satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
found := sequence.FindLast(func(v int) bool {
return v > 3
})
fmt.Println(found.MustGet())
}
Output: 5
func (Sequence[E]) Flush ¶
func (s Sequence[E]) Flush()
Flush consumes all elements of the input sequence.
Example ¶
package main
import (
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
sequence.Flush()
// No output expected
}
Output:
func (Sequence[E]) Fold ¶
Fold applies a function against an accumulator and each element in the sequence (from left to right) to reduce it to a single value.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
sum := sequence.Fold(func(agg, item int) int {
return agg + item
})
fmt.Println(sum.MustGet())
}
Output: 15
func (Sequence[E]) FoldRight ¶
FoldRight applies a function against an accumulator and each element in the sequence (from right to left) to reduce it to a single value.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of("a", "b", "c"))
concat := sequence.FoldRight(func(agg, item string) string {
return agg + item
})
fmt.Println(concat.MustGet())
}
Output: cba
func (Sequence[E]) ForEach ¶
ForEach calls the consumer for each element of the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq.AsSequence(seq.Of(1, 2, 3)).ForEach(func(v int) {
fmt.Println(v)
})
}
Output: 1 2 3
func (Sequence[E]) IsEmpty ¶
IsEmpty returns true if the sequence is empty.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of[int]())
isEmpty := sequence.IsEmpty()
fmt.Println(isEmpty)
}
Output: true
func (Sequence[E]) IsNotEmpty ¶
IsNotEmpty returns true if the sequence is not empty.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
isNotEmpty := sequence.IsNotEmpty()
fmt.Println(isNotEmpty)
}
Output: true
func (Sequence[E]) Limit ¶
Limit returns a new sequence that contains only the first n elements of the given sequence. SQL-like alias for Take
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
limited := sequence.Limit(2)
result := limited.Collect()
fmt.Println(result)
}
Output: [1 2]
func (Sequence[E]) None ¶
None returns true if no element satisfies the predicate.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
none := sequence.None(func(v int) bool {
return v > 5
})
fmt.Println(none)
}
Output: true
func (Sequence[E]) NotContains ¶
NotContains returns true if the element is not in the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
notContains := sequence.NotContains(6)
fmt.Println(notContains)
}
Output: true
func (Sequence[E]) Offset ¶
Offset returns a new sequence that skips the first n elements of the given sequence. SQL-like alias for Skip
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
offset := sequence.Offset(2)
result := offset.Collect()
fmt.Println(result)
}
Output: [3 4 5]
func (Sequence[E]) Partition ¶
Partition splits the sequence into chunks of the given size.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
partitions := sequence.Partition(2)
for partition := range partitions {
fmt.Println(seq.Collect(partition))
}
}
Output: [1 2] [3 4] [5]
func (Sequence[E]) Prepend ¶
Prepend prepends elements to the beginning of a sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(3, 4, 5))
prepended := sequence.Prepend(1, 2)
result := prepended.Collect()
fmt.Println(result)
}
Output: [1 2 3 4 5]
func (Sequence[E]) Repeat ¶
Repeat repeats the sequence count times.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
repeated := sequence.Repeat(2)
result := repeated.Collect()
fmt.Println(result)
}
Output: [1 2 3 1 2 3]
func (Sequence[E]) Reverse ¶
Reverse returns a new sequence with elements in reverse order.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
reversed := sequence.Reverse()
result := reversed.Collect()
fmt.Println(result)
}
Output: [3 2 1]
func (Sequence[E]) Skip ¶
Skip returns a new sequence that skips the first n elements of the given sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
skipped := sequence.Skip(2)
result := skipped.Collect()
fmt.Println(result)
}
Output: [3 4 5]
func (Sequence[E]) Take ¶
Take returns a new sequence that contains only the first n elements of the given sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
taken := sequence.Take(3)
result := taken.Collect()
fmt.Println(result)
}
Output: [1 2 3]
func (Sequence[E]) Tap ¶
Tap returns a new sequence that calls the consumer for each element of the sequence.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3)).Tap(func(v int) {
fmt.Println(v)
})
sequence.Flush()
}
Output: 1 2 3
func (Sequence[E]) ToSlice ¶
func (s Sequence[E]) ToSlice(slice []E) []E
ToSlice collects the elements of the sequence into a given slice.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3))
var slice []int
result := sequence.ToSlice(slice)
fmt.Println(result)
}
Output: [1 2 3]
func (Sequence[E]) Union ¶
Union returns a new sequence that contains all distinct elements from both input sequences.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.AsSequence(seq.Of(1, 2, 3))
seq2 := seq.AsSequence(seq.Of(3, 4, 5))
union := seq1.Union(seq2)
result := union.Collect()
fmt.Println(result)
}
Output: [1 2 3 4 5]
func (Sequence[E]) UnionAll ¶
UnionAll returns a new sequence that contains all elements from both input sequences.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
seq1 := seq.AsSequence(seq.Of(1, 2, 3))
seq2 := seq.AsSequence(seq.Of(3, 4, 5))
unionAll := seq1.UnionAll(seq2)
result := unionAll.Collect()
fmt.Println(result)
}
Output: [1 2 3 3 4 5]
func (Sequence[E]) Uniq ¶
Uniq returns a new sequence with only unique elements.
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 2, 3, 3, 3))
unique := sequence.Uniq()
result := unique.Collect()
fmt.Println(result)
}
Output: [1 2 3]
func (Sequence[E]) Where ¶
Where returns a new sequence with elements that satisfy the predicate. SQL-like alias for Filter
Example ¶
package main
import (
"fmt"
"github.com/go-softwarelab/common/pkg/seq"
)
func main() {
sequence := seq.AsSequence(seq.Of(1, 2, 3, 4, 5))
filtered := sequence.Where(func(v int) bool {
return v%2 == 0
})
result := filtered.Collect()
fmt.Println(result)
}
Output: [2 4]