🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

flyd-eithers

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flyd-eithers

A utility library for using Eithers in flyd streams

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

Flyd-Eithers

A utility library for working with Eithers in flyd streams.

This allows for error bubbling and safe transformations within flyd streams. Examples below.

API

Dependencies

You need to provide your own Either constructor/lib/implementation. This lib was tested with Eithers from both Sanctuary and Data.Either.

Example Usage

var S = require('Sanctuary');
var flydEithers = require('flyd-eithers')(S);
var flyd = require('flyd');

var a = flyd.stream();
var c = flydEithers
  .toEither(a)
  .map(function(x) { return x + 1; })
  .scan(function(acc, x) { return acc + x; }, S.Right(10));

flyd.on(function(x) {
  console.log(x);
}, c);

var count = 0;
setInterval(function() {
  count++;
  a(count);
}, 1000);

// Right(12);
// Right(15);
// etc..

Error Example

var S = require('Sanctuary');
var flydEithers = require('flyd-eithers')(S);
var flyd = require('flyd');

var a = flyd.stream();
var c = flydEithers
  .toEither(a)
  .map(function(x) { return x + 1; })
  .scan(function(acc, x) { return acc + x; }, S.Right(10));

flyd.on(function(x) {
  console.log(x);
}, c);

function mockHttpRequest() {
  setTimeout(function() {
    a(S.Left('error 404'));
  }, 100);
}

mockHttpRequest();

// Left('error 404') // Safe travel through map and scan :)

Keywords

functional

FAQs

Package last updated on 01 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts