1.0.3 • Published 3 years ago

monadic-bind v1.0.3

Weekly downloads
37
License
GPL-3.0-only
Repository
-
Last release
3 years ago

The bind (a.k.a. chain) operator, Haskell's >>=, implemented for plain native JavaScript types, as a function.

Namely for:

  • Array, works like Haskell's List Monad
  • number, unusual, perhaps, you're free to ignore it. But in JavaScript, NaN is sort of an empty value within the number type...
  • string, not treated as a "[Char]", however, you can just .split() it to an Array<string>
  • T | null | undefined, works like Haskell's Maybe

FAQ

Show me an example!

import {bind} from "monadic-bind";

const u = getUserOrNull("Joe")
bind(u, printUser);

Why not data-last?

TypeScript's type inference is left to right, putting the data argument first helps it infer the function argument's type.

Anyway, data-last only makes sense if the language has automatic currying, which JavaScript doesn't.

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago