Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iter/chain.go → it/chain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter
package it

import "iter"

Expand Down
28 changes: 14 additions & 14 deletions iter/chain_test.go → it/chain_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter_test
package it_test

import (
"fmt"
Expand All @@ -8,18 +8,18 @@ import (
"testing"

"github.com/BooleanCat/go-functional/v2/internal/assert"
fn "github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/it"
)

func ExampleChain() {
numbers := slices.Collect(fn.Chain(slices.Values([]int{1, 2}), slices.Values([]int{3, 4})))
numbers := slices.Collect(it.Chain(slices.Values([]int{1, 2}), slices.Values([]int{3, 4})))

fmt.Println(numbers)
// Output: [1 2 3 4]
}

func ExampleChain_method() {
numbers := fn.Iterator[int](slices.Values([]int{1, 2})).Chain(slices.Values([]int{3, 4})).Collect()
numbers := it.Iterator[int](slices.Values([]int{1, 2})).Chain(slices.Values([]int{3, 4})).Collect()

fmt.Println(numbers)
// Output: [1 2 3 4]
Expand All @@ -28,15 +28,15 @@ func ExampleChain_method() {
func TestChainEmpty(t *testing.T) {
t.Parallel()

assert.Empty[int](t, slices.Collect(fn.Chain[int]()))
assert.Empty[int](t, slices.Collect(it.Chain[int]()))
}

func TestChainMany(t *testing.T) {
t.Parallel()

numbers := slices.Collect(fn.Chain(
numbers := slices.Collect(it.Chain(
slices.Values([]int{1, 2}),
fn.Take(fn.Drop(fn.Count[int](), 3), 2),
it.Take(it.Drop(it.Count[int](), 3), 2),
slices.Values([]int{5, 6}),
))

Expand All @@ -46,19 +46,19 @@ func TestChainMany(t *testing.T) {
func TestChainTerminateEarly(t *testing.T) {
t.Parallel()

_, stop := iter.Pull(fn.Chain(slices.Values([]int{1, 2}), slices.Values([]int{3, 4})))
_, stop := iter.Pull(it.Chain(slices.Values([]int{1, 2}), slices.Values([]int{3, 4})))
stop()
}

func ExampleChain2() {
pairs := maps.Collect(fn.Chain2(maps.All(map[string]int{"a": 1}), maps.All(map[string]int{"b": 2})))
pairs := maps.Collect(it.Chain2(maps.All(map[string]int{"a": 1}), maps.All(map[string]int{"b": 2})))

fmt.Println(len(pairs))
// Output: 2
}

func ExampleChain2_method() {
pairs := fn.Iterator2[string, int](maps.All(map[string]int{"a": 1})).Chain(maps.All(map[string]int{"b": 2}))
pairs := it.Iterator2[string, int](maps.All(map[string]int{"a": 1})).Chain(maps.All(map[string]int{"b": 2}))

fmt.Println(len(maps.Collect(iter.Seq2[string, int](pairs))))
// Output: 2
Expand All @@ -67,7 +67,7 @@ func ExampleChain2_method() {
func TestChain2(t *testing.T) {
t.Parallel()

pairs := maps.Collect(fn.Chain2(maps.All(map[string]int{"a": 1}), maps.All(map[string]int{"b": 2})))
pairs := maps.Collect(it.Chain2(maps.All(map[string]int{"a": 1}), maps.All(map[string]int{"b": 2})))

assert.Equal(t, 2, len(pairs))
assert.Equal(t, pairs["a"], 1)
Expand All @@ -77,13 +77,13 @@ func TestChain2(t *testing.T) {
func TestChain2Empty(t *testing.T) {
t.Parallel()

assert.Equal(t, len(maps.Collect(fn.Chain2[int, int]())), 0)
assert.Equal(t, len(maps.Collect(it.Chain2[int, int]())), 0)
}

func TestChain2Many(t *testing.T) {
t.Parallel()

pairs := maps.Collect(fn.Chain2(
pairs := maps.Collect(it.Chain2(
maps.All(map[string]int{"a": 1}),
maps.All(map[string]int{"b": 2}),
maps.All(map[string]int{"c": 3}),
Expand All @@ -98,6 +98,6 @@ func TestChain2Many(t *testing.T) {
func TestChain2TerminateEarly(t *testing.T) {
t.Parallel()

_, stop := iter.Pull2(fn.Chain2(maps.All(map[string]int{"a": 1})))
_, stop := iter.Pull2(it.Chain2(maps.All(map[string]int{"a": 1})))
stop()
}
2 changes: 1 addition & 1 deletion iter/channel.go → it/channel.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter
package it

import "iter"

Expand Down
16 changes: 8 additions & 8 deletions iter/channel_test.go → it/channel_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package iter_test
package it_test

import (
"fmt"
"slices"
"testing"

"github.com/BooleanCat/go-functional/v2/internal/assert"
fn "github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/it"
)

func ExampleFromChannel() {
Expand All @@ -18,7 +18,7 @@ func ExampleFromChannel() {
items <- 2
}()

for number := range fn.FromChannel(items) {
for number := range it.FromChannel(items) {
fmt.Println(number)
}

Expand All @@ -34,7 +34,7 @@ func TestFromChannelYieldFalse(t *testing.T) {
defer close(numbersChan)

numbersChan <- 1
numbers := fn.FromChannel(numbersChan)
numbers := it.FromChannel(numbersChan)

var a int
numbers(func(value int) bool {
Expand All @@ -50,11 +50,11 @@ func TestFromChannelEmpty(t *testing.T) {
channel := make(chan int)
close(channel)

assert.Empty[int](t, slices.Collect(fn.FromChannel(channel)))
assert.Empty[int](t, slices.Collect(it.FromChannel(channel)))
}

func ExampleToChannel() {
channel := fn.ToChannel(slices.Values([]int{1, 2, 3}))
channel := it.ToChannel(slices.Values([]int{1, 2, 3}))

for number := range channel {
fmt.Println(number)
Expand All @@ -67,7 +67,7 @@ func ExampleToChannel() {
}

func ExampleToChannel_method() {
channel := fn.Iterator[int](slices.Values([]int{1, 2, 3})).ToChannel()
channel := it.Iterator[int](slices.Values([]int{1, 2, 3})).ToChannel()

for number := range channel {
fmt.Println(number)
Expand All @@ -82,7 +82,7 @@ func ExampleToChannel_method() {
func TestToChannelEmpty(t *testing.T) {
t.Parallel()

for range fn.ToChannel(slices.Values([]int{})) {
for range it.ToChannel(slices.Values([]int{})) {
t.Error("unexpected")
}
}
2 changes: 1 addition & 1 deletion iter/count.go → it/count.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter
package it

import "iter"

Expand Down
8 changes: 4 additions & 4 deletions iter/count_test.go → it/count_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package iter_test
package it_test

import (
"fmt"
"iter"
"testing"

fn "github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/it"
)

func ExampleCount() {
for i := range fn.Count[int]() {
for i := range it.Count[int]() {
if i >= 3 {
break
}
Expand All @@ -26,6 +26,6 @@ func ExampleCount() {
func TestCountTerminateEarly(t *testing.T) {
t.Parallel()

_, stop := iter.Pull(fn.Count[int]())
_, stop := iter.Pull(it.Count[int]())
stop()
}
2 changes: 1 addition & 1 deletion iter/cycle.go → it/cycle.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter
package it

import "iter"

Expand Down
16 changes: 8 additions & 8 deletions iter/cycle_test.go → it/cycle_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter_test
package it_test

import (
"fmt"
Expand All @@ -8,18 +8,18 @@ import (
"testing"

"github.com/BooleanCat/go-functional/v2/internal/assert"
fn "github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/it"
)

func ExampleCycle() {
numbers := slices.Collect(fn.Take(fn.Cycle(slices.Values([]int{1, 2})), 5))
numbers := slices.Collect(it.Take(it.Cycle(slices.Values([]int{1, 2})), 5))

fmt.Println(numbers)
// Output: [1 2 1 2 1]
}

func ExampleCycle_method() {
numbers := fn.Iterator[int](slices.Values([]int{1, 2})).Cycle().Take(5).Collect()
numbers := it.Iterator[int](slices.Values([]int{1, 2})).Cycle().Take(5).Collect()

fmt.Println(numbers)
// Output: [1 2 1 2 1]
Expand All @@ -28,7 +28,7 @@ func ExampleCycle_method() {
func TestCycleYieldFalse(t *testing.T) {
t.Parallel()

numbers := fn.Cycle(slices.Values([]int{1, 2}))
numbers := it.Cycle(slices.Values([]int{1, 2}))
var a int
numbers(func(value int) bool {
a = value
Expand All @@ -38,14 +38,14 @@ func TestCycleYieldFalse(t *testing.T) {
}

func ExampleCycle2() {
numbers := maps.Collect(fn.Take2(fn.Cycle2(maps.All(map[int]string{1: "one"})), 5))
numbers := maps.Collect(it.Take2(it.Cycle2(maps.All(map[int]string{1: "one"})), 5))

fmt.Println(numbers)
// Output: map[1:one]
}

func ExampleCycle2_method() {
numbers := fn.Iterator2[int, string](maps.All(map[int]string{1: "one"})).Cycle().Take(5)
numbers := it.Iterator2[int, string](maps.All(map[int]string{1: "one"})).Cycle().Take(5)

fmt.Println(maps.Collect(iter.Seq2[int, string](numbers)))
// Output: map[1:one]
Expand All @@ -54,7 +54,7 @@ func ExampleCycle2_method() {
func TestCycle2YieldFalse(t *testing.T) {
t.Parallel()

numbers := fn.Cycle2(maps.All(map[int]string{1: "one"}))
numbers := it.Cycle2(maps.All(map[int]string{1: "one"}))
var (
a int
b string
Expand Down
2 changes: 1 addition & 1 deletion iter/drop.go → it/drop.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter
package it

import "iter"

Expand Down
26 changes: 13 additions & 13 deletions iter/drop_test.go → it/drop_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter_test
package it_test

import (
"fmt"
Expand All @@ -8,11 +8,11 @@ import (
"testing"

"github.com/BooleanCat/go-functional/v2/internal/assert"
fn "github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/it"
)

func ExampleDrop() {
for value := range fn.Drop(slices.Values([]int{1, 2, 3, 4, 5}), 2) {
for value := range it.Drop(slices.Values([]int{1, 2, 3, 4, 5}), 2) {
fmt.Println(value)
}

Expand All @@ -23,7 +23,7 @@ func ExampleDrop() {
}

func ExampleDrop_method() {
for value := range fn.Iterator[int](slices.Values([]int{1, 2, 3, 4, 5})).Drop(2) {
for value := range it.Iterator[int](slices.Values([]int{1, 2, 3, 4, 5})).Drop(2) {
fmt.Println(value)
}

Expand All @@ -36,7 +36,7 @@ func ExampleDrop_method() {
func TestDropYieldFalse(t *testing.T) {
t.Parallel()

numbers := fn.Drop(slices.Values([]int{1, 2, 3, 4, 5}), 2)
numbers := it.Drop(slices.Values([]int{1, 2, 3, 4, 5}), 2)
var a int
numbers(func(value int) bool {
a = value
Expand All @@ -48,18 +48,18 @@ func TestDropYieldFalse(t *testing.T) {
func TestDropEmpty(t *testing.T) {
t.Parallel()

assert.Empty[int](t, slices.Collect(fn.Drop(fn.Exhausted[int](), 2)))
assert.Empty[int](t, slices.Collect(it.Drop(it.Exhausted[int](), 2)))
}

func ExampleDrop2() {
numbers := maps.Collect(fn.Drop2(maps.All(map[int]string{1: "one", 2: "two", 3: "three"}), 1))
numbers := maps.Collect(it.Drop2(maps.All(map[int]string{1: "one", 2: "two", 3: "three"}), 1))

fmt.Println(len(numbers))
// Output: 2
}

func ExampleDrop2_method() {
numbers := fn.Iterator2[int, string](maps.All(map[int]string{1: "one", 2: "two", 3: "three"})).Drop(1)
numbers := it.Iterator2[int, string](maps.All(map[int]string{1: "one", 2: "two", 3: "three"})).Drop(1)

fmt.Println(len(maps.Collect(iter.Seq2[int, string](numbers))))
// Output: 2
Expand All @@ -71,7 +71,7 @@ func TestDrop2(t *testing.T) {
keys := []int{1, 2, 3}
values := []string{"one", "two", "three"}

numbers := maps.Collect(fn.Drop2(fn.Zip(slices.Values(keys), slices.Values(values)), 1))
numbers := maps.Collect(it.Drop2(it.Zip(slices.Values(keys), slices.Values(values)), 1))

assert.Equal(t, len(numbers), 2)

Expand All @@ -83,22 +83,22 @@ func TestDrop2(t *testing.T) {
func TestDrop2Empty(t *testing.T) {
t.Parallel()

assert.Equal(t, len(maps.Collect(fn.Drop2(fn.Exhausted2[int, int](), 1))), 0)
assert.Equal(t, len(maps.Collect(it.Drop2(it.Exhausted2[int, int](), 1))), 0)
}

func TestDrop2Zero(t *testing.T) {
t.Parallel()

numbers := maps.Collect(fn.Drop2(maps.All(map[int]string{1: "one", 2: "two", 3: "three"}), 0))
numbers := maps.Collect(it.Drop2(maps.All(map[int]string{1: "one", 2: "two", 3: "three"}), 0))

assert.Equal(t, len(numbers), 3)
}

func TestDrop2YieldFalse(t *testing.T) {
t.Parallel()

numbersZipped := fn.Zip(slices.Values([]int{1, 2, 3}), slices.Values([]int{3, 4, 5}))
numbers := fn.Drop2(numbersZipped, 2)
numbersZipped := it.Zip(slices.Values([]int{1, 2, 3}), slices.Values([]int{3, 4, 5}))
numbers := it.Drop2(numbersZipped, 2)
var a, b int
numbers(func(v, w int) bool {
a, b = v, w
Expand Down
2 changes: 1 addition & 1 deletion iter/enumerate.go → it/enumerate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package iter
package it

import "iter"

Expand Down
Loading