Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Fjl Data.Maybe and Data.Either implementations in javascript (WIP (work-in-progress)).

License

Notifications You must be signed in to change notification settings

functional-jslib/fjl-data-core

Repository files navigation

Build Status GitHub version NPM version Dependencies

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:

  • 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.

Back to members list

alwaysMaybe

@todo - Added documentation here.

Back to members list

ap

@todo - Added documentation here.

Back to members list

Applicative

@todo - Added documentation here.

Back to members list

Apply

@todo - Added documentation here.

Back to members list

Bifunctor

@todo - Added documentation here.

Back to members list

either

@todo - Added documentation here.

Back to members list

flatMap

@todo - Added documentation here.

Back to members list

fmap

@todo - Added documentation here.

Back to members list

Functor

@todo - Added documentation here.

Back to members list

getMonadUnWrapper

@todo - Added documentation here.

Back to members list

IO

@todo - Added documentation here.

Back to members list

isJust

Signature: isJust(x: any): boolean

Back to members list

isLeft

Signature: isLeft(x: any): boolean

Back to members list

isMaybe

Signature: isMaybe(x: any): boolean

Back to members list

isMonad

@todo - Added documentation here.

Back to members list

isNothing

@todo - Added documentation here.

Back to members list

isRight

@todo - Added documentation here.

Back to members list

join

@todo - Added documentation here.

Back to members list

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);

Back to members list

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`

Back to members list

Left

@todo - Added documentation here.

Back to members list

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

Back to members list

maybeEqual

@todo - Added documentation here.

Back to members list

Monad

@todo - Added documentation here.

Back to members list

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`

Back to members list

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`

Back to members list

Right

@todo - Added documentation here.

Back to members list

toEither

@todo - Added documentation here.

Back to members list

toLeft

@todo - Added documentation here.

Back to members list

toMaybe

Gives you a Maybe if value is already a Maybe else gives you a Rightif value is notnullorundefined. Else gives you a Left`.

Back to members list

toRight

@todo - Added documentation here.

Back to members list

justUnWrapper(x: Just): (Just|*)

Removes one layer of structure from a Just.

Back to members list

unWrapMaybe

@todo - Added documentation here.

Back to members list

valueOf

@todo - Added documentation here.

Back to members list

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 of Just a or a Nothing. Example:
log(Maybe(99)) // Just(99)
log(Maybe(undefined)) // Nothing()
  • Maybe.Nothing - Always gives you a Nothing whether you're flatMaping maping or other etc. you'll always get a Nothing on Nothing. Example:
Nothing.map(x => (console.log('Hello World Big Bird'), 99)) === Nothing // true
  • Maybe.Just - @todo add description
  • Either.Right - @todo add description
  • Either.Left - @todo add description
  • IO - Functions similarly to es6 Promises but currently, they do not have bimap (then) functionality and/or catch functionality (will add functionality later).
  • Monad - Class for easily creating other monads (inherits Applicative, Apply and Functor 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.

Resources:

Change log

0.1.0