Skip to content

Instantly share code, notes, and snippets.

View ibnz36's full-sized avatar
:shipit:
💘 rust

víctor ibnz36

:shipit:
💘 rust
  • Barcelona
  • 17:28 (UTC +02:00)
View GitHub Profile
@ibnz36
ibnz36 / monad.ts
Created December 10, 2023 10:52
TypeScript Monad function
interface IMonad<T> {
andThen: <U>(fn: (value: T, finish: () => void) => U) => IMonad<U>;
}
export const Monad = <T>(initial: T, finished = false): IMonad<T> => {
if (finished) {
return {
andThen: <U>(_: (_: T, _: () => void) => U) => {
return Monad(null, true);
},