Coder Social home page Coder Social logo

akh-maybe's Introduction

Maybe Monad and Monad Transformer for Akh Javascript Monad Library

The MaybeT transformer, MaybeT, adds error control to a monad. The base type, Maybe, provides error logic on its own.

# To use as standalone package
$ npm install --save akh.maybe

# To use as part of akh library
$ npm install --save akh

Usage

MaybeT and Maybe implement the Fantasy Land monad, functor, and applicative functor interfaces.

Fantasy Land logo
// Maybe monad
require('akh.maybe').Maybe
require('akh').Maybe

// Maybe monad transformer
require('akh.maybe').MaybeT
require('akh').MaybeT

Maybe.run(m), m.run()

Perform a error computation m and return a maybe object result

Maybe.run(Maybe.just(3).map(x => -x)) === { just: true, value: -3 }
Maybe.run(Maybe.nothing.map(x => -x)) === { nothing: true }

MaybeT.run(t), t.run()

Same as Maybe.run but for a monad transformer. Returns an Maybe value inside of the inner monad.

Maybe.maybe(m, def), m.maybe(def)

Perform an maybe computation m and return the result if it succeeds and def if it fails.

Maybe Interface

Maybe.just(x)

MaybeT(m).just(x)

Same as Maybe.of. Success value.

Maybe.nothing

MaybeT(m).nothing

Error value

Contributing

Contributions are welcome.

To get started:

$ cd akh-maybe
$ npm install # install dev packages
$ npm test # run tests

akh-maybe's People

Contributors

janvogt avatar mattbierner avatar

Watchers

 avatar  avatar  avatar

Forkers

janvogt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.