npm

Need private packages and team management tools?Check out npm Orgs. »

@nll/datum

2.7.0 • Public • Published

An fp-ts style ADT to capture the concept of an Option in progress.

build status Coverage Status npm downloads

dependency status dev dependency status peer dependency status

@nll/datum

ADT for asynchronous data updated to work with fp-ts@2+.

Usage

Full Documentation

npm i @nll/datum fp-ts
import { sequenceT } from 'fp-ts/lib/Apply';
import { pipe } from 'fp-ts/lib/pipeable';
 
import {
  DatumEither,
  datumEither,
  failure,
  initial,
  map,
  pending,
  success,
  toRefresh,
} from '../src/DatumEither';
 
const sequence = sequenceT(datumEither);
 
// Here are some DatumEithers
const someInitial: DatumEither<string, string> = initial; // Type: Initial
const somePending: DatumEither<string, string> = pending; // Type: Pending
const someSuccess: DatumEither<string, string> = success('DATA!'); // Type: Replete<Right<string>>
const someFailure: DatumEither<string, string> = failure('ERROR!'); // Type: Replete<Left<string>>
 
// Here are some Refreshing Datume
const someRefreshingSuccess = toRefresh(someSuccess); // Type: Refresh<Right<string>>
const someRefreshingFailure = toRefresh(someFailure); // Type: Refresh<Left<string>>
 
const result1 = pipe(
  sequence(someInitial, somePending, someSuccess),
  map(([a, b, c]) => a + b + c)
);
console.log(result1);
/**
 * The initial short circuits the sequence
 * result1 === initial
 */
 
const result2 = pipe(
  sequence(someRefreshingSuccess, someRefreshingFailure),
  map(([a, b]) => a + b)
);
console.log(result2);
/**
 * The failure shortcircuits the sequence.
 * result2 === refresh(left('ERROR!'))
 */
 
const result3 = pipe(
  sequence(someSuccess, someRefreshingSuccess),
  map(([a, b]) => a + b)
);
console.log(result3);
/**
 * All values are good, so map is called, since one of the DatumEithers is refreshing, the sequence is refreshing
 * result3 = refresh(right('DATA!DATA!'))
 */

install

npm i @nll/datum

Downloadsweekly downloads

42

version

2.7.0

license

MPL-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability