All Projects → robertdp → purescript-wire

robertdp / purescript-wire

Licence: other
Events and Signals for FRP. Monad instances included

Programming Languages

purescript
368 projects
Dhall
116 projects

Projects that are alternatives of or similar to purescript-wire

HiFramework.Unity
Based on component to manage project's core logic and module used in unity3d
Stars: ✭ 22 (+69.23%)
Mutual labels:  event, signal
fine
🧹 Gracefully shutdown Node.js application: help you handle exit signals and cleanup
Stars: ✭ 20 (+53.85%)
Mutual labels:  event, signal
acto
A signals library for functional reactive programming
Stars: ✭ 18 (+38.46%)
Mutual labels:  signal, frp
Eventpp
Minimal C++ Event Bus
Stars: ✭ 69 (+430.77%)
Mutual labels:  event, signal
PCF8575 library
Library to use i2c digital expander with arduino, esp8266 and esp32. Can read write digital value with only 2 wire (perfect for ESP-01).
Stars: ✭ 28 (+115.38%)
Mutual labels:  wire
XLR8
Android Fastboot Utility Tool-Can do everything xD
Stars: ✭ 27 (+107.69%)
Mutual labels:  frp
akeneo-events-api-bundle
The Events API Bundle for Akeneo PIM delivers catalog changes as events to a 3rd party systems.
Stars: ✭ 18 (+38.46%)
Mutual labels:  event
hepipe.js
Pipe arbitrary data rows (logs, events, cdrs, esl, etc) to HEP Server (HOMER)
Stars: ✭ 22 (+69.23%)
Mutual labels:  event
add2calendar
📆 Allow you to add event to calendar easier
Stars: ✭ 51 (+292.31%)
Mutual labels:  event
reactive-rs
Streams and broadcasts: functional reactive programming in Rust.
Stars: ✭ 28 (+115.38%)
Mutual labels:  frp
EasyBuzzer
The Beep Library For Arduino
Stars: ✭ 63 (+384.62%)
Mutual labels:  signal
covidbot
Multi-platform messenger bot which provides updates on current COVID19 situation for Germany
Stars: ✭ 51 (+292.31%)
Mutual labels:  signal
league-lazy-event
💤 Provides a LazyListener for use with League\Event which allows for lazy fetching of actual listeners.
Stars: ✭ 14 (+7.69%)
Mutual labels:  event
website
Website of the JSCraftCamp in Munich
Stars: ✭ 35 (+169.23%)
Mutual labels:  event
wire
FedWire funds service file parser and writer. The HTTP server is available in a Docker image and the Go package is available.
Stars: ✭ 52 (+300%)
Mutual labels:  wire
signalstickers-client
⚙️🐍 A Python client for the Signal stickers API
Stars: ✭ 48 (+269.23%)
Mutual labels:  signal
RacJS
implementation of RAC(OC) on JavaScript and replacement of RxJS
Stars: ✭ 13 (+0%)
Mutual labels:  signal
three-onEvent
Add an EventListener for Object3d in your three.js project.(support click,hover or gaze)
Stars: ✭ 55 (+323.08%)
Mutual labels:  event
dtask
DTask is a scheduler for statically dependent tasks.
Stars: ✭ 17 (+30.77%)
Mutual labels:  frp
Swift-3-Functional-Programming
Code repository for Swift 3 Functional Programming, published by Packt
Stars: ✭ 78 (+500%)
Mutual labels:  frp

purescript-wire

Wire aims to provide useful reactive tools: currently Event and Signal.

Wire.Event

Event models asynchronous, discreet events over time, and are roughly analogous to Observables in RxJS.

Note: this implementation was largely inspired by FRP.Event from the purescript-event library. My implementation has a more restricted set of functionality, has immediate unsubscription (which works better when combined with React), and a monad instance.

Creating an event

create :: forall a. Effect { event :: Event a, push :: a -> Effect Unit }

Example:

periodically :: Milliseconds -> Effect (Event Unit)
periodically (Milliseconds ms) = do
  { event, push } <- Event.create
  setInterval (Math.floor ms) do
    push unit
  pure event

Subscribing to an event

subscribe :: forall a b. Event a -> (a -> Effect b) -> Effect (Effect Unit)

Example:

logToConsole :: forall a. Show a => Event a -> Effect (Effect Unit)
logToConsole event = Event.subscribe event Console.logShow

The Effect Unit being returned from Event.subscribe is the subscription canceller.

Extra functionality

  • fold :: forall a b. (b -> a -> b) -> b -> Event a -> Event b
  • share :: forall a. Event a -> Effect (Event a) (see #12)
  • distinct :: forall a. Eq a => Event a -> Event a
  • bufferUntil :: forall b a. Event a -> Event b -> Event (Array a)
  • fromFoldable :: forall a f. Foldable f => f a -> Event a
  • range :: Int -> Int -> Event Int
  • times :: Int -> Event Int

Wire.Signal

Signal is like Event but it models a continuous value over time, with change events. As such you can always read the current value of a signal, as well as subscribe to future changes. Signals are build on top of Event, and also have a monad instance.

This was originally created for modelling application-level reactive state in React, for things like routing and user authentication.

Creating a signal

create :: forall a. a -> Effect { signal :: Signal a, modify :: (a -> a) -> Effect Unit }

Example:

createAuthSignal :: Effect { auth :: Signal (Maybe AuthData), login :: AuthData -> Effect Unit, logout :: Effect Unit }
createAuthSignal = do
  { signal, modify } <- Signal.create Nothing
  pure
    { auth: signal
    , login: \authData -> modify (const (Just authData))
    , logout: modify (const Nothing)
    }

Sampling a signal

read :: forall a. Signal a -> Effect a

Subscribing to a signal

Subscribing to a signal is identical to events, with one exception: in the current implementation a signal will push it's current value to a new subscriber immediately (kind of like a ReplaySubject(1)).

subscribe :: forall b a. Signal a -> (a -> Effect b) -> Effect (Effect Unit)

Extra functionality

  • distinct :: forall a. Eq a => Signal a -> Signal a
  • event :: forall a. Signal a -> Event a
  • share :: forall a. Signal a -> Effect (Signal a)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].