From 1224a8382cf7ec0e9409430f7185d0f857a2ec26 Mon Sep 17 00:00:00 2001 From: rowan Date: Wed, 26 Mar 2025 21:42:55 -0500 Subject: [PATCH] add readme --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..810e15d --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# kojima +a small functional/monad library + +# Usage +## Example +```js +import { Identity, Some, None, Left, Right, Ok, Err } from 'kojima' + +const i = Identity(1) +const thou = Identity(1) +i.bind(x => thou.map(y => x + y)) // Identity(2) + +const maybe = Some('thing') +maybe.isSome() // true +const isnt = maybe.bind(() => None).map(_x => 'other') // None +isnt.isSome() // false + +const either = Right('neutron') + +const value = either.match({ + Right(value) { + return value + }, + Left(value) { + console.error('oh no') + } +}) // 'neutron' + +const result = Ok('3:41am') +result.isOk() // true + +result.bind(() => new Error(-Infinity)) + .map(_x => '4:10am') + +result.isErr() // true +``` +