Skip to content

mapogolions/streams

Repository files navigation

Basic event streams for OCaml(BuckleScript)

Build Status

Inspired by - Basic event streams for javascript

Disclaimers

  • 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

Introduction

OOP programming consider a stream as an object. On the other hand, in functional programming a stream is a higher order function.

OOP (zen-observable)

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')
  });

FP

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)

API

module Stream


Setup

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published