Mirror: 馃帺 A tiny but capable push & pull stream library for TypeScript and Flow
at v1.4.4 842 B view raw
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 => curry(sink => { 11 let state = { 12 value: ls, 13 ended: false, 14 looping: false, 15 pull: false 16 }; 17 18 sink(.Start((.signal) => { 19 switch (signal, state.looping) { 20 | (Pull, false) => { 21 state.pull = true; 22 state.looping = true; 23 24 while (state.pull && !state.ended) { 25 switch (state.value) { 26 | [x, ...rest] => { 27 state.value = rest; 28 state.pull = false; 29 sink(.Push(x)); 30 } 31 | [] => { 32 state.ended = true; 33 sink(.End); 34 } 35 } 36 }; 37 38 state.looping = false; 39 } 40 | (Pull, true) => state.pull = true 41 | (Close, _) => state.ended = true 42 } 43 })); 44});