General versions of Haskell's data Maybe a
, data Either a b
, and data IO a * -> *
implementations in javascript (note these implementations are monadic implementations that include their functor counter parts as part of said monadic structures).
- Requirements
- Getting Started
- Docs
- Motivation
- Development
- Supported Platforms
- License
- Resources
- Change log
- Javascript Ecmascript 5+.
- IE9+, and all other modern day browsers.
- 8+
import {...} from 'fjl-data-core';
const {...} = require('fjl-data-core');
See desired export type below:
- './dist/amd/' - Asynchronous module format.
- './dist/cjs/' - CommonJs module format.
- './dist/umd/' - Universal module definition format.
- './dist/iife/' - Immediately Invoked Function Execution - (exports
fjlMutable
as a global). - './dist/es6-module/' - Ecmascript 6 module format.
JSDocs are here (https://functional-jslib.github.io/fjl-data-core/) [https://functional-jslib.github.io/fjl-data-core/].
Functor, [Apply](#apply), [Applicative](#applicative), [Bifunctor](#bifunctor), [Monad](#monad), [isMonad](#ismonad), [valueOf](#valueof), [join](#join),
[fmap](#fmap), [ap](#ap), [flatMap](#flatmap), [getMonadUnWrapper](#getmonadunwrapper), [IO](#io), [Just](#just), [isJust](#isjust), [just](#just), [Nothing](#nothing),
[isNothing](#isnothing), [nothing](#nothing), [maybe](#maybe), [unWrapJust](#unwrapjust), [unWrapMaybe](#unwrapmaybe), [maybeEqual](#maybeequal), [isMaybe](#ismaybe),
[toMaybe](#tomaybe), [Left](#left), [Right](#right), [left](#left), [right](#right), [isRight](#isright), [isLeft](#isleft), [toRight](#toright), [toLeft](#toleft),
[toEither](#toeither), [either](#either)
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
Signature: isJust(x: any): boolean
Signature: isLeft(x: any): boolean
Signature: isMaybe(x: any): boolean
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
Signature: class Just(x): Just<x>
Just
monad - Wraps given value in a Just
and gives
you a monad interface (functor + apply + applicative + monad);
Signature: just (x: any): Just<x>
Wraps given value in a Just
(same as Just
except in method form); E.g.:
import {just} from 'fjl-data-core';
console.log(
just(99).map(x => x * 2).value === 99 * 2
); // `true`
@todo - Added documentation here.
Signature: maybe(replacement :*, a => b, Maybe(a)) :(b|replacement)
Returns replacment
value if Maybe(a)
is a Nothing
else maps
a => b
operation on Maybe(a)
;
Haskell Type (fyi):
maybe :: b -> (a -> b) -> Maybe a -> b
@todo - Added documentation here.
@todo - Added documentation here.
Signature: Nothing(): Nothing
Always returns Nothing
singleton; Even when called with new
; E.g.:
import {Nothing} from 'fjl-data-core';
import {log} from 'fjl';
log(
Nothing() === new Nothing()
) // `true`
Same as Nothing
except in method form; E.g.:
import {nothing} from 'fjl-data-core';
import {log} from 'fjl';
log(
nothing() === Nothing() && nothing() === new Nothing()
) // `true`
@todo - Added documentation here.
@todo - Added documentation here.
@todo - Added documentation here.
Gives you a Maybe
if value is already a Maybe
else gives you a Rightif value is not
nullor
undefined. Else gives you a
Left`.
@todo - Added documentation here.
Removes one layer of structure from a Just
.
@todo - Added documentation here.
@todo - Added documentation here.
Wraps given value in a maybe; Value gets wrapped in a Just
if
it is non-empty (not equal to undefined
or null
), else returns Nothing
.
Removes one layer of structure from monad.
import {join, just, maybeEqual} from 'fjl-data-core';
import {compose, log} from 'fjl';
compose(log, maybeEqual(just(99)), join, just, just)(99); // `true`
Maybe
- Gives you an either ofJust a
or aNothing
. Example:
log(Maybe(99)) // Just(99)
log(Maybe(undefined)) // Nothing()
Maybe.Nothing
- Always gives you aNothing
whether you'reflatMap
ingmap
ing or other etc. you'll always get aNothing
onNothing
. Example:
Nothing.map(x => (console.log('Hello World Big Bird'), 99)) === Nothing // true
Maybe.Just
- @todo add descriptionEither.Right
- @todo add descriptionEither.Left
- @todo add descriptionIO
- Functions similarly to es6Promise
s but currently, they do not havebimap
(then
) functionality and/orcatch
functionality (will add functionality later).Monad
- Class for easily creating other monads (inheritsApplicative
,Apply
andFunctor
from './src/...').- @todo add other members
- For commands see './package.json' scripts.
- Everything is in './src'.
- Distribution is in './dist'.
- Docs are in './docs'.
Using jest
(see './package.json' scripts).
BSD 3 Clause - Included in sources.