Skip to content

Commit 6876ab7

Browse files
committed
Merge branch 'main' into date-format-functions-with-options
2 parents a3c5f9e + e386832 commit 6876ab7

20 files changed

+2435
-493
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
# @rescript/core Changelog
22

3-
## master
3+
## main
4+
5+
### API changes
6+
7+
- Change `Map.set` to not return self, to indicate that it's mutable. https://github.com/rescript-association/rescript-core/pull/34
8+
- Change `Set.add` to not return self, to indicate that it's mutable. https://github.com/rescript-association/rescript-core/pull/35
9+
- Change `Iterator` bindings to have the same shape as `AsyncIterator` for consistency. https://github.com/rescript-association/rescript-core/pull/34
10+
- Add `Iterator.toArray` binding for turning an iterator into an array. https://github.com/rescript-association/rescript-core/pull/34
11+
12+
### Documentation
13+
14+
- Docstrings for `Map` and `Iterator`. https://github.com/rescript-association/rescript-core/pull/34
15+
- Docstrings for `Global`. https://github.com/rescript-association/rescript-core/pull/39
16+
- Docstrings for `Set`. https://github.com/rescript-association/rescript-core/pull/35
17+
- Docstrings for `AsyncIterator`. https://github.com/rescript-association/rescript-core/pull/33
18+
- Docstrings for `Type`. https://github.com/rescript-association/rescript-core/pull/32
19+
- Docstrings for `Int`. https://github.com/rescript-association/rescript-core/pull/37
20+
- Docstrings for `Dict`. https://github.com/rescript-association/rescript-core/pull/40

src/Core__AsyncIterator.resi

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/***
2+
Bindings to async iterators, a way to do async iteration in JavaScript.
3+
4+
See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) on MDN.*/
5+
6+
/**
7+
The type representing an async iterator.
8+
*/
9+
type t<'a>
10+
11+
type value<'a> = {
12+
/**
13+
Whether there are more values to iterate on before the iterator is done.
14+
*/
15+
done: bool,
16+
/**
17+
The value of this iteration, if any.
18+
*/
19+
value: option<'a>,
20+
}
21+
22+
/**
23+
`next(asyncIterator)`
24+
25+
Returns the next value of the iterator, if any.
26+
27+
See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) on MDN.
28+
29+
## Examples
30+
- A simple example, getting the next value:
31+
```rescript
32+
let {done, value} = await someAsyncIterator->AsyncIterator.next
33+
```
34+
35+
- Complete example, including looping over all values:
36+
```rescript
37+
// Let's pretend we get an async iterator returning ints from somewhere.
38+
@val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator"
39+
40+
41+
let processMyAsyncIterator = async () => {
42+
// ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop.
43+
let break = ref(false)
44+
45+
while !break.contents {
46+
// Await the next iterator value
47+
let {value, done} = await asyncIterator->AsyncIterator.next
48+
49+
// Exit the while loop if the iterator says it's done
50+
break := done
51+
52+
// This will log the (int) value of the current async iteration, if a value was returned.
53+
Console.log(value)
54+
}
55+
}
56+
```
57+
*/
58+
@send
59+
external next: t<'a> => promise<value<'a>> = "next"

src/Core__Console.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
@val external trace: unit => unit = "console.trace"
2626

27-
@val external timeStart: string => unit = "console.timeStart"
27+
@val external time: string => unit = "console.time"
2828
@val external timeEnd: string => unit = "console.timeEnd"

0 commit comments

Comments
 (0)