LoginSignup
4
1

More than 5 years have passed since last update.

JavaScriptの関数型言語風のライブラリmonet

Posted at

undefinedとnullの扱いがめんどくさくてMaybeはできないのかと探したらmonetというライブラリがあった。
FunctionalJavaやScalazを参考に開発しているようでかなり使いやすそう。Maybe・Either・IO・Listなどなどがあるが今回はMaybeさえ使えればよかったのでこだけ紹介する。

インストールはnpmでいつものように。

$ npm install --save monet

次のような感じで使う。

import monet from 'monet'

const m = monet.Maybe.fromNull(x)
const a = m.map( o => doSomething(o)).orJust(foo)

他の言語でMaybeやOptionalを使ったことがあればすぐにわかるだろう。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1