···11+MIT License
22+33+Copyright (c) 2018 Phil Plückthun
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
+12
README.md
···11+# Wonka
22+33+A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
44+55+> “There’s no earthly way of knowing<br>
66+> Which direction we are going<br>
77+> There’s no knowing where we’re rowing<br>
88+> Or which way the river’s flowing” - **Willy Wonka**
99+1010+<br>
1111+1212+
+27-27
__tests__/callbag_test.re
__tests__/wonka_test.re
···11open Jest;
22-open Callbag_types;
22+open Wonka_types;
3344let it = test;
55···99 open! Expect.Operators;
10101111 it("sends list items to a puller sink", () => {
1212- let source = Callbag.fromList([10, 20, 30]);
1313- let talkback = ref((_: Callbag_types.talkbackT) => ());
1212+ let source = Wonka.fromList([10, 20, 30]);
1313+ let talkback = ref((_: Wonka_types.talkbackT) => ());
1414 let signals = [||];
15151616 source(signal => {
···3535 open Expect; open! Expect.Operators;
36363737 it("sends array items to a puller sink", () => {
3838- let source = Callbag.fromArray([| 10, 20, 30 |]);
3939- let talkback = ref((_: Callbag_types.talkbackT) => ());
3838+ let source = Wonka.fromArray([| 10, 20, 30 |]);
3939+ let talkback = ref((_: Wonka_types.talkbackT) => ());
4040 let signals = ref([||]);
41414242 source(signal => {
···58585959 it("does not blow up the stack when iterating something huge", () => {
6060 let arr = Array.make(100000, 123);
6161- let source = Callbag.fromArray(arr);
6262- let talkback = ref((_: Callbag_types.talkbackT) => ());
6161+ let source = Wonka.fromArray(arr);
6262+ let talkback = ref((_: Wonka_types.talkbackT) => ());
6363 let values = [||];
64646565 source(signal => {
···8888 it("maps all emissions of a source", () => {
8989 let num = ref(1);
9090 let nums = [||];
9191- let talkback = ref((_: Callbag_types.talkbackT) => ());
9191+ let talkback = ref((_: Wonka_types.talkbackT) => ());
92929393- Callbag.map((_) => {
9393+ Wonka.map((_) => {
9494 let res = num^;
9595 num := num^ + 1;
9696 res
···125125 it("filters emissions according to a predicate", () => {
126126 let i = ref(1);
127127 let nums = [||];
128128- let talkback = ref((_: Callbag_types.talkbackT) => ());
128128+ let talkback = ref((_: Wonka_types.talkbackT) => ());
129129130130- Callbag.filter(x => x mod 2 === 0, sink => {
130130+ Wonka.filter(x => x mod 2 === 0, sink => {
131131 sink(Start(signal => {
132132 switch (signal) {
133133 | Pull => {
···162162 it("folds emissions using an initial seed value", () => {
163163 let i = ref(1);
164164 let nums = [||];
165165- let talkback = ref((_: Callbag_types.talkbackT) => ());
165165+ let talkback = ref((_: Wonka_types.talkbackT) => ());
166166167167- Callbag.scan((acc, x) => acc + x, 0, sink => {
167167+ Wonka.scan((acc, x) => acc + x, 0, sink => {
168168 sink(Start(signal => {
169169 switch (signal) {
170170 | Pull => {
···198198 open! Expect.Operators;
199199200200 it("merges different sources into a single one", () => {
201201- let a = Callbag.fromList([1, 2, 3]);
202202- let b = Callbag.fromList([4, 5, 6]);
203203- let talkback = ref((_: Callbag_types.talkbackT) => ());
201201+ let a = Wonka.fromList([1, 2, 3]);
202202+ let b = Wonka.fromList([4, 5, 6]);
203203+ let talkback = ref((_: Wonka_types.talkbackT) => ());
204204 let signals = [||];
205205- let source = Callbag.merge([| a, b |]);
205205+ let source = Wonka.merge([| a, b |]);
206206207207 source(signal => {
208208 switch (signal) {
···226226 open Expect;
227227228228 it("shares an underlying source with all sinks", () => {
229229- let talkback = ref((_: Callbag_types.talkbackT) => ());
229229+ let talkback = ref((_: Wonka_types.talkbackT) => ());
230230 let num = ref(1);
231231 let nums = [||];
232232233233- let source = Callbag.share(sink => {
233233+ let source = Wonka.share(sink => {
234234 sink(Start(signal => {
235235 switch (signal) {
236236 | Pull => {
···269269 open Expect;
270270271271 it("combines the latest values of two sources", () => {
272272- let talkback = ref((_: Callbag_types.talkbackT) => ());
272272+ let talkback = ref((_: Wonka_types.talkbackT) => ());
273273274274 let makeSource = (factor: int) => {
275275 let num = ref(1);
···290290291291 let sourceA = makeSource(1);
292292 let sourceB = makeSource(2);
293293- let source = Callbag.combine(sourceA, sourceB);
293293+ let source = Wonka.combine(sourceA, sourceB);
294294 let res = [||];
295295296296 source(signal => {
···311311 open Expect;
312312313313 it("only lets a maximum number of values through", () => {
314314- let talkback = ref((_: Callbag_types.talkbackT) => ());
314314+ let talkback = ref((_: Wonka_types.talkbackT) => ());
315315 let num = ref(1);
316316317317- let source = Callbag.take(2, sink => sink(Start(signal => {
317317+ let source = Wonka.take(2, sink => sink(Start(signal => {
318318 switch (signal) {
319319 | Pull => {
320320 let i = num^;
···364364 }));
365365 };
366366367367- Callbag.forEach(x => ignore(Js.Array.push(x, nums)), source);
367367+ Wonka.forEach(x => ignore(Js.Array.push(x, nums)), source);
368368 expect(nums) |> toEqual([| 0, 1, 2, 3 |])
369369 });
370370 });
···379379 let actual = [||];
380380381381 input
382382- |> Callbag.fromArray
383383- |> Callbag.map(x => string_of_int(x))
384384- |> Callbag.forEach(x => ignore(Js.Array.push(x, actual)));
382382+ |> Wonka.fromArray
383383+ |> Wonka.map(x => string_of_int(x))
384384+ |> Wonka.forEach(x => ignore(Js.Array.push(x, actual)));
385385386386 expect(output) |> toEqual(output)
387387 });