Skip to content

Commit cce964b

Browse files
committed
rename to Seq.unfoldMany
1 parent 36038f8 commit cce964b

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Version 4.4.0
1+
## Version 4.4.1
22

3-
- `Seq.expand` is new and similar to `Seq.unfold` but recursively generates a sequence of sequences.
3+
- `Seq.unfoldMany` is new and similar to `Seq.unfold` but recursively generates a sequence of sequences.
44

55
## Version 4.3.0
66

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let cons: ('a, t<'a>) => t<'a>
5656
let cycle: t<'a> => t<'a>
5757
let delay: (unit => t<'a>) => t<'a>
5858
let empty: t<'a>
59-
let expand: ('a, 'a => t<('b, 'a)>) => t<t<'b>>
59+
let unfoldMany: ('a, 'a => t<('b, 'a)>) => t<t<'b>>
6060
let forever: 'a => t<'a>
6161
let foreverWith: (unit => 'a) => t<'a>
6262
let fromArray: (~start: int=?, ~end: int=?, array<'a>) => t<'a>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jmagaram/rescript-seq",
3-
"version": "4.4.0",
3+
"version": "4.4.1",
44
"module": "",
55
"description": "Lazy sequences for ReScript.",
66
"keywords": [

src/Seq.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ let iterateWhile = (seed, f) => () => {
953953
Next(seed, go(seed))
954954
}
955955

956-
let rec expand = (seed, f) =>
956+
let rec unfoldMany = (seed, f) =>
957957
seed
958958
->f
959-
->flatMap(((n, seed)) => expand(seed, f)->map(result => cons(n, result)))
959+
->flatMap(((n, seed)) => unfoldMany(seed, f)->map(result => cons(n, result)))
960960
->orElse(empty->once)

src/Seq.resi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ Seq.unfold(1, i => i < 100 ? Some(i, i * 2) : None) // [1, 2, 4, 8, 16, 32, 64]
3636
let unfold: ('seed, 'seed => option<('a, 'seed)>) => t<'a>
3737

3838
/**
39-
`expand(seed, f)` creates a sequence of sequences through a recursive
40-
computation. Similar to `unfold`.
39+
`unfoldMany(seed, f)` creates a sequence of sequences through a recursive
40+
computation.
4141
*/
42-
let expand: ('seed, 'seed => t<('a, 'seed)>) => t<t<'a>>
42+
let unfoldMany: ('seed, 'seed => t<('a, 'seed)>) => t<t<'a>>
4343

4444
/**
4545
`init(count, f)` initializes a sequence based on a `count` and a function `f`

tests/Seq__SeqTests.res

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ let unfoldTests =
797797
),
798798
])
799799

800-
let expandTests = {
800+
let unfoldManyTests = {
801801
// for a given seed string, return each character and a new seed which is all
802802
// the characters that follow it
803803
let combos = s => {
@@ -815,14 +815,19 @@ let expandTests = {
815815
->Seq.fromArray
816816

817817
makeSeqEqualsTests(
818-
~title="expand",
818+
~title="unfoldMany",
819819
[
820-
(S.expand("abcd", combos)->format, ["abcd", "abd", "acd", "ad", "bcd", "bd", "cd", "d"], ""),
821-
(S.expand("abc", combos)->format, ["abc", "ac", "bc", "c"], ""),
822-
(S.expand("ab", combos)->format, ["ab", "b"], ""),
823-
(S.expand("a", combos)->format, ["a"], ""),
824820
(
825-
S.expand("abcdefghijklmnopqrstuv", combos)
821+
S.unfoldMany("abcd", combos)->format,
822+
["abcd", "abd", "acd", "ad", "bcd", "bd", "cd", "d"],
823+
"",
824+
),
825+
(S.unfoldMany("abc", combos)->format, ["abc", "ac", "bc", "c"], ""),
826+
(S.unfoldMany("ab", combos)->format, ["ab", "b"], ""),
827+
(S.unfoldMany("a", combos)->format, ["a"], ""),
828+
(S.unfoldMany("", combos)->format, [""], ""),
829+
(
830+
S.unfoldMany("abcdefghijklmnopqrstuv", combos)
826831
->Seq.last
827832
->Option.map(s => s->Seq.once->format)
828833
->Option.getExn,
@@ -2265,7 +2270,7 @@ let tests =
22652270
everySomeTests,
22662271
everyTests,
22672272
exactlyOneTests,
2268-
expandTests,
2273+
unfoldManyTests,
22692274
filterMapiTests,
22702275
filterMapTests,
22712276
filterOkTests,

0 commit comments

Comments
 (0)