File tree Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change 10
10
- The ` dynamic ` module gains the ` option ` function.
11
11
- The ` uri ` module gains the ` percent_encode ` and ` percent_decode ` functions.
12
12
- The ` os ` module gains the ` erlang_timestamp ` function.
13
- - The ` iterator ` module gains the ` append ` , ` flatten ` and ` flat_map ` functions.
13
+ - The ` iterator ` module gains the ` append ` , ` flatten ` , ` flat_map ` and ` step `
14
+ functions.
14
15
15
16
## v0.11.0 - 2020-08-22
16
17
Original file line number Diff line number Diff line change @@ -168,6 +168,34 @@ pub fn to_list(iterator: Iterator(element)) -> List(element) {
168
168
|> list . reverse
169
169
}
170
170
171
+ /// Eagerly access the first value of an interator, returning a `Next`
172
+ /// that contains the first value and the rest of the iterator.
173
+ ///
174
+ /// If called on an empty iterator, `Done` is returned.
175
+ ///
176
+ /// ## Examples
177
+ ///
178
+ /// > assert Next(head, tail) =
179
+ /// > [1, 2, 3, 4]
180
+ /// > |> from_list
181
+ /// > |> step
182
+ /// > head
183
+ /// 1
184
+ /// > tail |> to_list
185
+ /// [2, 3, 4]
186
+ ///
187
+ /// > []
188
+ /// > |> from_list
189
+ /// > |> step
190
+ /// Done
191
+ ///
192
+ pub fn step ( iterator : Iterator ( e) ) -> Step ( e, Iterator ( e) ) {
193
+ case iterator . continuation ( ) {
194
+ Stop -> Done
195
+ Continue ( e , a ) -> Next ( e , Iterator ( a ) )
196
+ }
197
+ }
198
+
171
199
fn do_take (
172
200
continuation : fn ( ) -> Action ( e) ,
173
201
desired : Int ,
Original file line number Diff line number Diff line change 1
1
import gleam/should
2
- import gleam/iterator
2
+ import gleam/iterator . { Done , Next }
3
3
import gleam/list
4
4
5
5
// a |> from_list |> to_list == a
@@ -17,6 +17,30 @@ pub fn to_from_list_test() {
17
17
test ( [ 1 , 2 , 4 , 8 ] )
18
18
}
19
19
20
+ pub fn step_test ( ) {
21
+ let test = fn ( subject ) {
22
+ let step =
23
+ subject
24
+ |> iterator . from_list
25
+ |> iterator . step
26
+
27
+ case subject {
28
+ [ ] ->
29
+ step
30
+ |> should . equal ( Done )
31
+
32
+ [ h , .. t ] ->
33
+ step
34
+ |> should . equal ( Next ( h , iterator . from_list ( t ) ) )
35
+ }
36
+ }
37
+
38
+ test ( [ ] )
39
+ test ( [ 1 ] )
40
+ test ( [ 1 , 2 ] )
41
+ test ( [ 1 , 2 , 3 ] )
42
+ }
43
+
20
44
// a |> from_list |> take(n) == a |> list.take(_, n)
21
45
pub fn take_test ( ) {
22
46
let test = fn ( n , subject ) {
You can’t perform that action at this time.
0 commit comments