https://github.com/kutyel/what-is-a-monad-ts
Learn what Monads™️ are in TypeScript!
https://github.com/kutyel/what-is-a-monad-ts
applicative fp fp-ts functor js learning-exercise monad monads
Last synced: 7 months ago
JSON representation
Learn what Monads™️ are in TypeScript!
- Host: GitHub
- URL: https://github.com/kutyel/what-is-a-monad-ts
- Owner: kutyel
- License: mit
- Created: 2020-10-20T10:57:40.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-08T07:40:51.000Z (about 4 years ago)
- Last Synced: 2025-02-02T01:43:40.531Z (9 months ago)
- Topics: applicative, fp, fp-ts, functor, js, learning-exercise, monad, monads
- Language: TypeScript
- Homepage: https://codesandbox.io/s/monads-in-javascript-d0hgm?file=/src/index.js
- Size: 362 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# what-is-a-monad-ts
[](https://github.com/prettier/prettier)
[](https://travis-ci.org/kutyel/what-is-a-monad-ts)
[](https://coveralls.io/github/kutyel/what-is-a-monad-ts)Learn what Monads™️ are in TypeScript!
```typescript
/**
* The `Monad` type class combines the operations of the `Chain` and
* `Applicative` type classes. Therefore, `Monad` instances represent type
* constructors which support sequential composition, and also lifting of
* functions of arbitrary arity.
*
* Instances must satisfy the following laws in addition to the `Applicative` and `Chain` laws:
*
* 1. Left identity: `M.chain(M.of(a), f) <--> f(a)`
* 2. Right identity: `M.chain(fa, M.of) <--> fa`
*
* Note. `Functor`'s `map` can be derived: `A.map = (fa, f) => A.chain(fa, a => A.of(f(a)))`
*
*/
export interface Nothing {
readonly _tag: 'Nothing'
}export interface Just {
readonly _tag: 'Just'
readonly value: A
}export type Maybe = Nothing | Just
```