1open Wonka_types;
2
3type fromListState('a) = {
4 mutable value: 'a,
5 mutable ended: bool,
6 mutable looping: bool,
7 mutable pull: bool,
8};
9
10let fromList = ls =>
11 curry(sink => {
12 let state = {value: ls, ended: false, looping: false, pull: false};
13
14 sink(.
15 Start(
16 (. signal) =>
17 switch (signal, state.looping) {
18 | (Pull, false) =>
19 state.pull = true;
20 state.looping = true;
21
22 while (state.pull && !state.ended) {
23 switch (state.value) {
24 | [x, ...rest] =>
25 state.value = rest;
26 state.pull = false;
27 sink(. Push(x));
28 | [] =>
29 state.ended = true;
30 sink(. End);
31 };
32 };
33
34 state.looping = false;
35 | (Pull, true) => state.pull = true
36 | (Close, _) => state.ended = true
37 },
38 ),
39 );
40 });