Coder Social home page Coder Social logo

akh-writer's Introduction

Writer Monad and Monad Transformer for Akh Javascript Monad Library

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

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

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

Usage

WriterT and Writer implement the Fantasy Land monad, functor, and applicative functor interfaces.

Fantasy Land logo
// Writer monad
require('akh.writer').Writer
require('akh').Writer

// Writer monad transformer
require('akh.writer').WriterT
require('akh').WriterT

Writer.run(m, w), m.run(w)

Perform a writer computation m without output monoid w and return { value, output}

WriterT.run(t, w), t.run(w)

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

Writer.exec(m, w), m.exec(w)

Perform a writer computation m without output monoid w and return resulting value

Writer Interface

Writer.tell(b)

WriterT(M).tell(b)

Append b to the output.

Writer.of(4)
    .chain(x => writer.tell(List.of('output1')).map(_ => x)))
    .run(List.zero) === { value: 4, output: List of ['output1'] }

Writer.listen()

WriterT(M).listen()

Produces the current value output pair as { value, output }

m.pass()

t.pass()

Exec current monad which returns a [value, f], then modify current output with f and return value.

m.censor(f)

t.censor(f)

Exec current monad, then modify current output with f and return original value.

Contributing

Contributions are welcome.

To get started:

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

akh-writer's People

Contributors

mattbierner avatar seance avatar

Watchers

 avatar  avatar  avatar

Forkers

seance

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.