Skip to content

Commit 0f84f0b

Browse files
bloodyowlzth
authored andcommitted
Add Array.fromIterator for convenience
1 parent c2fa6d3 commit 0f84f0b

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Core__Array.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
external getUnsafe: (array<'a>, int) => 'a = "%array_unsafe_get"
44
external setUnsafe: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
55

6+
@val external fromIterator: Core__Iterator.t<'a> => array<'a> = "Array.from"
67
@val external fromArrayLike: Js.Array2.array_like<'a> => array<'a> = "Array.from"
78
@val
89
external fromArrayLikeWithMap: (Js.Array2.array_like<'a>, 'a => 'b) => array<'b> = "Array.from"

src/Core__Array.resi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO: Docs
2+
@val external fromIterator: Core__Iterator.t<'a> => array<'a> = "Array.from"
3+
14
// TODO: Docs
25
@val external fromArrayLike: Js.Array2.array_like<'a> => array<'a> = "Array.from"
36

test/ArrayTests.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,28 @@ Test.run([
401401

402402
})), eq, undefined);
403403

404+
Test.run([
405+
[
406+
"ArrayTests.res",
407+
103,
408+
13,
409+
27
410+
],
411+
"fromIterator"
412+
], Array.from(new Map([
413+
[
414+
1,
415+
3
416+
],
417+
[
418+
2,
419+
4
420+
]
421+
]).values()), eq, [
422+
3,
423+
4
424+
]);
425+
404426
export {
405427
eq ,
406428
}

test/ArrayTests.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ Test.run(
9898
eq,
9999
None,
100100
)
101+
102+
Test.run(
103+
__POS_OF__("fromIterator"),
104+
Array.fromIterator(Map.fromArray([(1, 3), (2, 4)])->Map.values),
105+
eq,
106+
[3, 4],
107+
)

0 commit comments

Comments
 (0)