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

Configure Feed

Select the types of activity you want to include in your feed.

Update README

+19 -62
+19 -62
README.md
··· 28 28 It exposes a set of helpers to create and transform sources and output sinks, meaning it helps you to turn an event source or an 29 29 iterable set of data into streams, and manipulate these streams. 30 30 31 - ## Why it exists 32 - 33 31 Reason has been becoming increasingly popular, but it's missing a good pattern for streams that feels native to the language. 34 32 The functional nature of callbags make them a perfect starting point to fix this, and to introduce a reactive programming 35 33 pattern to a language that is well suited for it. 36 34 37 - Hence `Wonka` is a library that aims to make complex streams of data easy to deal with. 35 + This library also attempts to support as many Reason/JS environments as possible, which makes the adoption of streams across 36 + multiple projects a lot easier. Hence `Wonka` is a library that aims to make complex streams of data easy to deal with. 37 + 38 + ## Compatibility 39 + 40 + `Wonka` is not only compatible with Reason/Bucklescript, but out of the box with other environments as well. 41 + 42 + - TypeScript 43 + - JS/Flow 44 + - Reason/OCaml Bucklescript 45 + - Reason/OCaml `bs-native` 46 + - Reason/OCaml Dune 47 + 48 + In summary, it should work in any TypeScript/Flow/Reason/OCaml environment with full type safety. 38 49 39 50 ## Installation 40 51 41 52 Install the library first: `yarn add wonka` or `npm install --save wonka`, 42 53 43 - Then add `wonka` to `bs-dependencies` in your `bsconfig.json` file like so: 54 + ### BuckleScript 55 + 56 + For Bucklescript you will also need to add `wonka` to `bs-dependencies` in your `bsconfig.json` file like so: 44 57 45 58 ```diff 46 59 { ··· 54 67 } 55 68 ``` 56 69 57 - ## Getting Started 58 - 59 - Writing your first stream is very easy! Let's suppose you would like to create a stream from a list, filter out some values, 60 - then map over the remaining ones, and lastly iterate over the final values. 61 - 62 - This can be done with a few operators that might remind you of functions you would also call on iterables. 63 - 64 - ```reason 65 - let example = [1, 2, 3, 4, 5, 6]; 66 - 67 - Wonka.fromList(example) 68 - |> Wonka.filter((.x) => x mod 2 === 0) 69 - |> Wonka.map((.x )=> x * 2) 70 - |> Wonka.forEach((.x) => print_endline(string_of_int(x))); 71 - 72 - /* prints: 4, 8, 12 */ 73 - ``` 74 - 75 - To explain what's going on: 76 - 77 - - `fromList` creates a pullable source with values from the list 78 - - `filter` only lets even values through 79 - - `map` multiplies the values by `2` 80 - - `forEach` pulls values from the resulting source and prints them 81 - 82 - As you can see, all helpers that we've used are exposed on the `Wonka` module. 83 - But if we would like to use JavaScript-based APIs, then we need to use the `WonkaJs` module. 84 - 85 - Let's look at the same example, but instead of a list we will use an `interval` stream. 86 - This stream will output ascending numbers starting from `0` indefinitely. 87 - 88 - We will code the same example as before but we'd like the `interval` to push 89 - a new number every `50ms` and to stop after seven values. 90 - 91 - ```reason 92 - WonkaJs.interval(50) 93 - |> Wonka.take(7) 94 - |> Wonka.filter((.x) => x mod 2 === 0) 95 - |> Wonka.map((.x) => x * 2) 96 - |> Wonka.forEach((.x) => print_endline(string_of_int(x))); 97 - 98 - /* prints: 4, 8, 12 */ 99 - ``` 100 - 101 - The last three functions stay the same, but we are now using `interval` as our source. 102 - This is a listenable source, meaning that it pushes values downwards when it sees fit. 103 - And the `take` operator tells our source to stop sending values after having received seven 104 - values. 105 - 106 - And already you have mastered all the basics of `Wonka` and learned about a couple of its operators! 107 - Go, you! :tada: 108 - 109 70 ## Documentation 110 71 111 - I am currently still working on getting some documentation up and running. Those will contain: 72 + This is still a work-in-progress but will contain full information on the following 73 + across all supported languages: 112 74 113 75 - The API, i.e. a list of all helpers 114 76 - Examples ··· 116 78 - Developer Guides (How to write a source/operator/sink) 117 79 - Modified Callbag spec 118 80 119 - Stay tuned and read the signature files in the meantime please: 120 - 121 - - [wonka.rei](./src/wonka.rei) 122 - - [wonkaJs.rei](./src/wonka.rei) 123 -