# kojima a small functional/monad library # Usage ## Example ```js import { Option, Some, None, Result, Ok, Err } from 'kojima' const maybe = Option.of('thing') maybe.isSome() // true const isnt = maybe.chain(None).map(_x => 'other') // None isnt.isSome() // false const result = Result.of('3:41am') result.isOk() // true result.chain(() => Err(new Error(-Infinity))) .map(_x => '4:10am') .chain(Ok) result.isErr() // true // crimes! None == None() // true ``` ## Documentation ### curry > (* -> a) -> (* -> a) Returns a curried equivalent of the provided function. ```js import { curry } from './curry.js' const add = (a, b, c) => a + b + c const curriedAdd = curry(add) const add1 = curriedAdd(1) const add3 = add1(2) const add4 = curriedAdd(2, 2) const six = add3(3) // 6 const eight = add4(2) // 7 const twelve = curriedAdd(4, 4, 4) // 12 ``` ### Option Represents a value which may not exist. #### Methods ##### of :: Option f => a -> f a > Option.of\(value: a) -> Option\ ##### zero :: Option f => () -> f a > Option.zero\(value: a) -> Option\ ##### chain :: Option m => m a ~> (a -> m b) -> m b > Option\.chain\(fn: (value: T) -> Option\) -> Option\ ##### map :: Option f => f a ~> (a -> b) -> f b > Option\.map\(fn: (value: T) -> U) -> Option\ ##### alt :: Option f => f a ~> f a -> f a > Option\.alt(other: Option\) -> Option\ ##### fold :: Option f => f a ~> ((b, a) -> b, b) -> b > Option\.fold\(fn: ((acc: U, value: T) -> U, initial: U) -> U) -> U ##### isSome :: Option f => () -> boolean > Option\.isSome() -> boolean ##### isNone :: Option f => () -> boolean > Option\.isNone() -> boolean ### Result Represents a value which may fail. #### Methods ##### of :: Result f => a -> f a > Result.of\(value: a) -> Result\ ##### zero :: Result f => () -> f a > Result.zero() -> Result\<(), ()\> ##### chain :: Result m => m a ~> (a -> m b) -> m b > Result\.chain\(fn: (value: T) -> Result) -> Result\ ##### map :: Result f => f a ~> (a -> b) -> f b > Result\.map\(fn: (value: T) -> U) -> Result\ ##### alt :: Result f => f a ~> f a -> f a > Result\.alt(other: Result\) -> Result\ ##### fold :: Result f => f a ~> ((b, a) -> b, b) -> b > Result\.fold\(fn: ((acc: U, value: T) -> U, initial: U) -> U) -> U ##### bimap :: Result f => f a c ~> (a -> b, c -> d) -> f b d > Result\.bimap\(x: (value: T1) -> T2, y: (error: E1) -> E2) -> Result\ ##### isOk :: Result f => () -> boolean > Result\.isOk() -> boolean ##### isErr :: Result f => () -> boolean > Result\.isErr() -> boolean