-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Match naming conventions for Seq on Count (-> NaturalNumbers)
- Loading branch information
1 parent
ac11494
commit e2bf45f
Showing
12 changed files
with
113 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package it | ||
|
||
import "iter" | ||
|
||
// Integers yields all integers in the range [start, stop) with the given step. | ||
func Integers[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64](start, stop, step V) iter.Seq[V] { | ||
return func(yield func(V) bool) { | ||
for i := start; i < stop; i += step { | ||
if !yield(i) { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
// NaturalNumbers yields all non-negative integers in ascending order. | ||
func NaturalNumbers[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64]() iter.Seq[V] { | ||
return func(yield func(V) bool) { | ||
var i V | ||
|
||
for { | ||
if !yield(i) { | ||
return | ||
} | ||
i++ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package it_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/BooleanCat/go-functional/v2/it" | ||
) | ||
|
||
func ExampleNaturalNumbers() { | ||
for i := range it.NaturalNumbers[int]() { | ||
if i >= 3 { | ||
break | ||
} | ||
|
||
fmt.Println(i) | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 | ||
} | ||
|
||
func ExampleIntegers() { | ||
for i := range it.Integers[uint](0, 3, 1) { | ||
fmt.Println(i) | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 | ||
} | ||
|
||
func TestIntegersYieldFalse(t *testing.T) { | ||
t.Parallel() | ||
|
||
numbers := it.Integers[uint](0, 3, 1) | ||
|
||
numbers(func(value uint) bool { | ||
return false | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package itx | ||
|
||
import "github.com/BooleanCat/go-functional/v2/it" | ||
|
||
// Integers yields all integers in the range [start, stop) with the given step. | ||
func Integers[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64](start, stop, step V) Iterator[V] { | ||
return Iterator[V](it.Integers[V](start, stop, step)) | ||
} | ||
|
||
// NaturalNumbers yields all non-negative integers in ascending order. | ||
func NaturalNumbers[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64]() Iterator[V] { | ||
return Iterator[V](it.NaturalNumbers[V]()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package itx_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/BooleanCat/go-functional/v2/it/itx" | ||
) | ||
|
||
func ExampleNaturalNumbers() { | ||
fmt.Println(itx.NaturalNumbers[int]().Take(4).Collect()) | ||
// Output: [0 1 2 3] | ||
} | ||
|
||
func ExampleIntegers() { | ||
fmt.Println(itx.Integers[uint](0, 3, 1).Collect()) | ||
// Output: [0 1 2] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters