···2828It exposes a set of helpers to create and transform sources and output sinks, meaning it helps you to turn an event source or an
2929iterable set of data into streams, and manipulate these streams.
30303131-## Why it exists
3232-3331Reason has been becoming increasingly popular, but it's missing a good pattern for streams that feels native to the language.
3432The functional nature of callbags make them a perfect starting point to fix this, and to introduce a reactive programming
3533pattern to a language that is well suited for it.
36343737-Hence `Wonka` is a library that aims to make complex streams of data easy to deal with.
3535+This library also attempts to support as many Reason/JS environments as possible, which makes the adoption of streams across
3636+multiple projects a lot easier. Hence `Wonka` is a library that aims to make complex streams of data easy to deal with.
3737+3838+## Compatibility
3939+4040+`Wonka` is not only compatible with Reason/Bucklescript, but out of the box with other environments as well.
4141+4242+- TypeScript
4343+- JS/Flow
4444+- Reason/OCaml Bucklescript
4545+- Reason/OCaml `bs-native`
4646+- Reason/OCaml Dune
4747+4848+In summary, it should work in any TypeScript/Flow/Reason/OCaml environment with full type safety.
38493950## Installation
40514152Install the library first: `yarn add wonka` or `npm install --save wonka`,
42534343-Then add `wonka` to `bs-dependencies` in your `bsconfig.json` file like so:
5454+### BuckleScript
5555+5656+For Bucklescript you will also need to add `wonka` to `bs-dependencies` in your `bsconfig.json` file like so:
44574558```diff
4659{
···5467}
5568```
56695757-## Getting Started
5858-5959-Writing your first stream is very easy! Let's suppose you would like to create a stream from a list, filter out some values,
6060-then map over the remaining ones, and lastly iterate over the final values.
6161-6262-This can be done with a few operators that might remind you of functions you would also call on iterables.
6363-6464-```reason
6565-let example = [1, 2, 3, 4, 5, 6];
6666-6767-Wonka.fromList(example)
6868- |> Wonka.filter((.x) => x mod 2 === 0)
6969- |> Wonka.map((.x )=> x * 2)
7070- |> Wonka.forEach((.x) => print_endline(string_of_int(x)));
7171-7272-/* prints: 4, 8, 12 */
7373-```
7474-7575-To explain what's going on:
7676-7777-- `fromList` creates a pullable source with values from the list
7878-- `filter` only lets even values through
7979-- `map` multiplies the values by `2`
8080-- `forEach` pulls values from the resulting source and prints them
8181-8282-As you can see, all helpers that we've used are exposed on the `Wonka` module.
8383-But if we would like to use JavaScript-based APIs, then we need to use the `WonkaJs` module.
8484-8585-Let's look at the same example, but instead of a list we will use an `interval` stream.
8686-This stream will output ascending numbers starting from `0` indefinitely.
8787-8888-We will code the same example as before but we'd like the `interval` to push
8989-a new number every `50ms` and to stop after seven values.
9090-9191-```reason
9292-WonkaJs.interval(50)
9393- |> Wonka.take(7)
9494- |> Wonka.filter((.x) => x mod 2 === 0)
9595- |> Wonka.map((.x) => x * 2)
9696- |> Wonka.forEach((.x) => print_endline(string_of_int(x)));
9797-9898-/* prints: 4, 8, 12 */
9999-```
100100-101101-The last three functions stay the same, but we are now using `interval` as our source.
102102-This is a listenable source, meaning that it pushes values downwards when it sees fit.
103103-And the `take` operator tells our source to stop sending values after having received seven
104104-values.
105105-106106-And already you have mastered all the basics of `Wonka` and learned about a couple of its operators!
107107-Go, you! :tada:
108108-10970## Documentation
11071111111-I am currently still working on getting some documentation up and running. Those will contain:
7272+This is still a work-in-progress but will contain full information on the following
7373+across all supported languages:
1127411375- The API, i.e. a list of all helpers
11476- Examples
···11678- Developer Guides (How to write a source/operator/sink)
11779- Modified Callbag spec
11880119119-Stay tuned and read the signature files in the meantime please:
120120-121121-- [wonka.rei](./src/wonka.rei)
122122-- [wonkaJs.rei](./src/wonka.rei)
123123-