Basic event streams for OCaml(BuckleScript)
Inspired by - Basic event streams for javascript
- Project motivation - learning by creating (I created this to learn the intricate details)
- No intended for production (I don't have a long term intent to maintain this project for real use)
- I'd suggest using a mature project basic-streams
OOP programming consider a stream as an object. On the other hand, in functional programming a stream is a higher order function.
const unsubscribe = Observable.of(1, 2, 3)
.map(x => x + 1)
.filter(x => x % 2 !== 0)
.subscribe({
next: value => console.log(value),
error: err => console.error(err),
done: () => console.log('done')
});
let unsubscribe = [1; 2; 3]
|> Stream.Async.of_list ~delay:1000
|> Stream.map (fun x -> x + 1)
|> Stream.filter (fun x -> x mod 2 <> 0)
|> Stream.subscribe (fun x -> x |> string_of_int |> print_endline)
- empty
- of_item
- later
- prepend
- scan
- skip
- skip_while
- take
- take_while
- chain
- chain_latest
- subcribe
- of_list
- of_list_reverse
- of_array
- of_array_reverse
- map
- map2
- map3
- filter
- ap
- merge
- Async.of_list
- Async.of_array
Node.js
git clone https://github.com/mapogolions/streams.git
cd streams
npm install
npm run build
npm run test
node src/app.bs.js
Browser
git clone https://github.com/mapogolions/streams.git
cd streams
npm install
npm run build
npm run test
npm run webpack
then open ./public/index.html
(no server needed!)
Clean up folder
npm run clean