Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow

Add initial readme and rename src and package

+21
LICENSE.md
···
+
MIT License
+
+
Copyright (c) 2018 Phil Plückthun
+
+
Permission is hereby granted, free of charge, to any person obtaining a copy
+
of this software and associated documentation files (the "Software"), to deal
+
in the Software without restriction, including without limitation the rights
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+
copies of the Software, and to permit persons to whom the Software is
+
furnished to do so, subject to the following conditions:
+
+
The above copyright notice and this permission notice shall be included in all
+
copies or substantial portions of the Software.
+
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+
SOFTWARE.
+12
README.md
···
+
# Wonka
+
+
A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
+
+
> “There’s no earthly way of knowing<br>
+
> Which direction we are going<br>
+
> There’s no knowing where we’re rowing<br>
+
> Or which way the river’s flowing” - **Willy Wonka**
+
+
<br>
+
+
![Wonka](/docs/wonka.jpg?raw=true)
+27 -27
__tests__/callbag_test.re __tests__/wonka_test.re
···
open Jest;
-
open Callbag_types;
+
open Wonka_types;
let it = test;
···
open! Expect.Operators;
it("sends list items to a puller sink", () => {
-
let source = Callbag.fromList([10, 20, 30]);
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let source = Wonka.fromList([10, 20, 30]);
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let signals = [||];
source(signal => {
···
open Expect; open! Expect.Operators;
it("sends array items to a puller sink", () => {
-
let source = Callbag.fromArray([| 10, 20, 30 |]);
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let source = Wonka.fromArray([| 10, 20, 30 |]);
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let signals = ref([||]);
source(signal => {
···
it("does not blow up the stack when iterating something huge", () => {
let arr = Array.make(100000, 123);
-
let source = Callbag.fromArray(arr);
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let source = Wonka.fromArray(arr);
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let values = [||];
source(signal => {
···
it("maps all emissions of a source", () => {
let num = ref(1);
let nums = [||];
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
-
Callbag.map((_) => {
+
Wonka.map((_) => {
let res = num^;
num := num^ + 1;
res
···
it("filters emissions according to a predicate", () => {
let i = ref(1);
let nums = [||];
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
-
Callbag.filter(x => x mod 2 === 0, sink => {
+
Wonka.filter(x => x mod 2 === 0, sink => {
sink(Start(signal => {
switch (signal) {
| Pull => {
···
it("folds emissions using an initial seed value", () => {
let i = ref(1);
let nums = [||];
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
-
Callbag.scan((acc, x) => acc + x, 0, sink => {
+
Wonka.scan((acc, x) => acc + x, 0, sink => {
sink(Start(signal => {
switch (signal) {
| Pull => {
···
open! Expect.Operators;
it("merges different sources into a single one", () => {
-
let a = Callbag.fromList([1, 2, 3]);
-
let b = Callbag.fromList([4, 5, 6]);
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let a = Wonka.fromList([1, 2, 3]);
+
let b = Wonka.fromList([4, 5, 6]);
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let signals = [||];
-
let source = Callbag.merge([| a, b |]);
+
let source = Wonka.merge([| a, b |]);
source(signal => {
switch (signal) {
···
open Expect;
it("shares an underlying source with all sinks", () => {
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let num = ref(1);
let nums = [||];
-
let source = Callbag.share(sink => {
+
let source = Wonka.share(sink => {
sink(Start(signal => {
switch (signal) {
| Pull => {
···
open Expect;
it("combines the latest values of two sources", () => {
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let makeSource = (factor: int) => {
let num = ref(1);
···
let sourceA = makeSource(1);
let sourceB = makeSource(2);
-
let source = Callbag.combine(sourceA, sourceB);
+
let source = Wonka.combine(sourceA, sourceB);
let res = [||];
source(signal => {
···
open Expect;
it("only lets a maximum number of values through", () => {
-
let talkback = ref((_: Callbag_types.talkbackT) => ());
+
let talkback = ref((_: Wonka_types.talkbackT) => ());
let num = ref(1);
-
let source = Callbag.take(2, sink => sink(Start(signal => {
+
let source = Wonka.take(2, sink => sink(Start(signal => {
switch (signal) {
| Pull => {
let i = num^;
···
}));
};
-
Callbag.forEach(x => ignore(Js.Array.push(x, nums)), source);
+
Wonka.forEach(x => ignore(Js.Array.push(x, nums)), source);
expect(nums) |> toEqual([| 0, 1, 2, 3 |])
});
});
···
let actual = [||];
input
-
|> Callbag.fromArray
-
|> Callbag.map(x => string_of_int(x))
-
|> Callbag.forEach(x => ignore(Js.Array.push(x, actual)));
+
|> Wonka.fromArray
+
|> Wonka.map(x => string_of_int(x))
+
|> Wonka.forEach(x => ignore(Js.Array.push(x, actual)));
expect(output) |> toEqual(output)
});
+1 -1
bsconfig.json
···
// http://bucklescript.github.io/bucklescript/docson/#build-schema.json
{
-
"name": "bs-callbag",
+
"name": "wonka",
"version": "0.1.0",
"bsc-flags": ["-bs-super-errors", "-bs-no-version-header"],
"refmt": 3,
docs/wonka.jpg

This is a binary file and will not be displayed.

+8 -5
package.json
···
{
-
"name": "bs-callbag",
+
"name": "wonka",
"version": "0.1.0",
"scripts": {
"clean": "bsb -clean-world",
···
"test:watch": "jest --watch"
},
"keywords": [
+
"wonka",
"reason",
"bucklescript",
"callbag",
+
"callback",
"observable",
-
"iterable"
+
"iterable",
+
"stream"
],
-
"repository": "https://github.com/kitten/bs-callbag",
-
"homepage": "https://github.com/kitten/bs-callbag",
-
"bugs": "https://github.com/kitten/bs-callbag/issues",
+
"repository": "https://github.com/kitten/wonka",
+
"homepage": "https://github.com/kitten/wonka",
+
"bugs": "https://github.com/kitten/wonka/issues",
"license": "MIT",
"devDependencies": {
"bs-jest": "^0.3.2",
+3 -3
src/callbag.re src/wonka.re
···
-
open Callbag_types;
-
open Callbag_helpers;
+
open Wonka_types;
+
open Wonka_helpers;
-
module Types = Callbag_types;
+
module Types = Wonka_types;
let fromList = (l, sink) => {
let restL = ref(l);
+1 -1
src/callbag.rei src/wonka.rei
···
-
open Callbag_types;
+
open Wonka_types;
/* -- source factories */
+1 -1
src/callbagJs.re src/wonkaJs.re
···
-
open Callbag_types;
+
open Wonka_types;
let interval = (p, sink) => {
let i = ref(0);
+1 -1
src/callbagJs.rei src/wonkaJs.rei
···
-
open Callbag_types;
+
open Wonka_types;
/* -- source factories */
+1 -1
src/callbag_helpers.re src/wonka_helpers.re
···
-
open Callbag_types;
+
open Wonka_types;
let captureTalkback = (source: (signalT('a) => unit) => unit, sinkWithTalkback: [@bs] (signalT('a), talkbackT => unit) => unit) => {
let talkback = ref((_: talkbackT) => ());
src/callbag_types.re src/wonka_types.re