Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

avoidwork/tiny-monad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny-monad

tiny-monad is a Monad factory to help get you started working with Monads. Monad() takes an optional modifier Function to run when instantiating instances, which receives monad & value as it's parameters. What's a Monad? Well, it's this pattern that makes composing Functions / behaviors really easy, and it works well with Functional Reactive Programming for creating UIs, etc..

var AlertMonad = Monad().lift('alert', alert),
    hello      = AlertMonad('Hello!'),
    goodbye    = AlertMonad('Goodbye!');

hello.alert();

...

goodbye.alert();

build status

API

bind

Method

Binds a Function to the Monad and executes it

param  {Function} fn Function to bind
return {Object}      Result of Monad value & fn

Example

var x = Monad();

x('Hello World').bind(alert);

lift

Method

Lifts a non-monadic function into the Monad

param  {String} name Name of Function
param  {String} fn   Function to 'lift'
return {Object}      Monad constructor

Example

var alertify = Monad().lift('alert', alert),
    instance = alertify('Hello World!');

instance.alert();

method

Method

Adds a function to the Monad prototype

param  {String} name Name of Function
param  {String} fn   Function
return {Object}      Monad constructor

Example

var alertify = Monad().method('alert', alert),
    instance = alertify('Hello World!');

instance.alert();

License

Copyright (c) 2014 Jason Mulligan
Licensed under the BSD-3 license.

About

tiny-monad is a Monad factory to help get you started working with Monads

Resources

License

Stars

Watchers

Forks

Packages

No packages published