You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

apropos

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apropos

Strong typed functional 'Either', 'Maybe', 'Identity' and 'Tuple'

0.6.2
latest
Source
npmnpm
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

Apropos

Fast strong typed 'Either' data structure for typescript and flow

$ npm install --save apropos

npm version Build Status

API

//@flow

import defaultOf, {
  of,
  ofL,
  Right,
  Left,
  is,
  makeError,
  type Apropos,
  type MakeError,
} from 'apropos'

of

function of<R>(value: R): Apropos<void, R>

Create pure right-handed value, left-handed type is empty. Exports by default

ofL

function ofL<L>(value: L): Apropos<L, void>

Create pure left-handed value, right-handed type is empty.

Right

function Right<-L, R>(value: R): Apropos<L, R>

Create right-handed value, left-handed type is inferred from usage. Technically, Right returns the same as of; the difference is only in the type inference.

Left

function Left<L, -R>(value: L): Apropos<L, R>

Create left-handed value, right-handed type is inferred from usage

is

function is<-T>(value: T): boolean

Checks whether an object is an instance of Apropos

makeError

class AnnotatedError<Context, Tag> extends Error {
  tag: Tag
  data: Context
}

function makeError<-Tag>(tag: Tag): <Context>(data: Context) => AnnotatedError<Context, Tag>

Create fabric for generating tagged error constructors. Useful in .mapL.

See annotated errors

Instance methods

  • isRight

  • isLeft

  • equals

  • thru

  • orElse

  • swap

  • promise

  • fold

Maps

  • map

  • mapR

  • mapL

  • bimap

Taps

  • tap

  • tapR

  • tapL

  • bitap

Chains

  • chain

  • chainR

  • chainL

  • bichain

Conditions

  • cond

  • chainCond

  • logic

Combinations

  • alt

  • and

  • ap

Annotated errors

import { of, makeError, MakeError, Left } from 'apropos'

const notNumber: MakeError<'Not a number'> = makeError('Not a number')
const isNegative: MakeError<'Negative number'> = makeError('Negative number')

const positiveNum =
  of(-2)
    .map(x => x + 1)
    .chain(x => typeof x === 'number'
      ? of(x)
      : Left(x))
    .mapL(notNumber)
    .logic({
      cond: x => x > 0,
      pass: x => 'Positive number: ' + x,
      fail: isNegative
    })

positiveNum.fold(x => console.log(x), x => console.error(x))

// => Annotated Error: 'Negative number' -1

The project is released under the Mit License

Keywords

either

FAQs

Package last updated on 15 Sep 2017

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