fjl-data-core (W.I.P. (work-in-progress))
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).
Sections in Readme:
- Requirements
- Getting Started
- Docs
- Motivation
- Development
- Supported Platforms
- License
- Resources
- Change log
Requirements:
- Javascript Ecmascript 5+.
Supported Platforms:
Browsers
- IE9+, and all other modern day browsers.
NodeJs
- 8+
Getting Started:
In NodeJs:
Using es2015 modules:
import {...} from 'fjl-data-core';
Using CommonJs modules:
const {...} = require('fjl-data-core');
In Browser:
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.
Docs
JSDocs are here (https://functional-jslib.github.io/fjl-data-core/) [https://functional-jslib.github.io/fjl-data-core/].
fjlDataCore
members
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)
toFunctor
@todo - Added documentation here.
alwaysMaybe
@todo - Added documentation here.
ap
@todo - Added documentation here.
Applicative
@todo - Added documentation here.
Apply
@todo - Added documentation here.
Bifunctor
@todo - Added documentation here.
either
@todo - Added documentation here.
flatMap
@todo - Added documentation here.
fmap
@todo - Added documentation here.
Functor
@todo - Added documentation here.
getMonadUnWrapper
@todo - Added documentation here.
IO
@todo - Added documentation here.
isJust
Signature: isJust(x: any): boolean
isLeft
Signature: isLeft(x: any): boolean
isMaybe
Signature: isMaybe(x: any): boolean
isMonad
@todo - Added documentation here.
isNothing
@todo - Added documentation here.
isRight
@todo - Added documentation here.
join
@todo - Added documentation here.
Just
Signature: class Just(x): Just<x>
Just
monad - Wraps given value in a Just
and gives
you a monad interface (functor + apply + applicative + monad);
just
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`
Left
@todo - Added documentation here.
maybe
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
maybeEqual
@todo - Added documentation here.
Monad
@todo - Added documentation here.
Nothing
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`
nothing(): Nothing
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`
Right
@todo - Added documentation here.
toEither
@todo - Added documentation here.
toLeft
@todo - Added documentation here.
toMaybe
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`.
toRight
@todo - Added documentation here.
justUnWrapper(x: Just): (Just|*)
Removes one layer of structure from a Just
.
unWrapMaybe
@todo - Added documentation here.
valueOf
@todo - Added documentation here.
isMaybe(x) :boolean
isMonad(x) :boolean
toMaybe(x) :(Just<x>|Nothing)
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
.
join(m :Monad) :Monad
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`
fmap(x => y, f :Functor) :Functor<y>
ap(x :Applicative, f :Functor) :Applicative
flatMap(fn: (x) => y, m :Monad<x>) :Monad<y>
getMonadUnWrapper(Type: Function) :(m: Monad) => *
trampoline(fn: Function) :*
class Monad (x) {}
Old docs below
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
Development:
- For commands see './package.json' scripts.
Dir structure
- Everything is in './src'.
- Distribution is in './dist'.
- Docs are in './docs'.
Testing
Using jest
(see './package.json' scripts).
License:
BSD 3 Clause - Included in sources.