All Projects → zerobias → apropos

zerobias / apropos

Licence: MIT license
Fast strong typed 'Either' data structure for typescript and flow

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to apropos

Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (+1745%)
Mutual labels:  functional, fp, monad
fnts
λ Minimal Functional Programming Utilities for TypeScript & JavaScript
Stars: ✭ 75 (+275%)
Mutual labels:  functional, fp, monad
hkts
Functional programming tools: option, either, task, state, optics, etc.
Stars: ✭ 20 (+0%)
Mutual labels:  functional, fp, monad
Morphism
⚡ Type-safe data transformer for JavaScript, TypeScript & Node.js.
Stars: ✭ 336 (+1580%)
Mutual labels:  functional, fp
Swiftz-Validation
A data structure for validations. It implements the applicative functor interface
Stars: ✭ 15 (-25%)
Mutual labels:  functional, fp
Eslint Plugin Functional
ESLint rules to disable mutation and promote fp in JavaScript and TypeScript.
Stars: ✭ 282 (+1310%)
Mutual labels:  functional, fp
Fun Task
Abstraction for managing asynchronous code in JS
Stars: ✭ 363 (+1715%)
Mutual labels:  fp, monad
Sup
Composable, purely functional healthchecks in Scala.
Stars: ✭ 138 (+590%)
Mutual labels:  functional, fp
Fkit
A functional programming toolkit for JavaScript.
Stars: ✭ 588 (+2840%)
Mutual labels:  functional, fp
Design-Patterns
Project for learning and discuss about design patterns
Stars: ✭ 16 (-20%)
Mutual labels:  fp, monad
tiinvo
Functions for tacit programming and functional types for TypeScript and JavaScript.
Stars: ✭ 36 (+80%)
Mutual labels:  monad, either
J-Curry
A Java library that enables applying Functional Programming concepts like currying and partial application for functions, also it supports types like Either, Try, etc... using RxJava 2 interfaces, compatible with Java 7 and above
Stars: ✭ 17 (-15%)
Mutual labels:  monad, either
pyroclastic
Functional dataflow through composable computations
Stars: ✭ 17 (-15%)
Mutual labels:  functional, fp
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+2590%)
Mutual labels:  fp, monad
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (-10%)
Mutual labels:  adt, either
Alembic
⚗️ Functional JSON Parser - Linux Ready 🐧
Stars: ✭ 115 (+475%)
Mutual labels:  functional, monad
php-slang
The place where PHP meets Functional Programming
Stars: ✭ 107 (+435%)
Mutual labels:  fp, monad
Monio
Async-capable IO monad for JS
Stars: ✭ 311 (+1455%)
Mutual labels:  fp, monad
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (+55%)
Mutual labels:  functional, monad
function-composition-cheatsheet
Composition of Functions
Stars: ✭ 24 (+20%)
Mutual labels:  fp, monad

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

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].