DEV Community

Discussion on: Building Expressive Monads in Javascript: Introduction

Collapse
 
suddenlygiovanni profile image
Giovanni Ravalico • Edited

TS Identity interfaces

interface IdentityMonad<A> {
  /**
   * method that just returns the value contained within.
   */
  emit: () => A

  /**
   * method which is intended to chain various monads together
   */
  chain: <B>(f: (x: A) => B) => B
  /**
   * `map` it is the chain function with a built-in rewrapping of the resulting value into a
   * new Identity, which itself can be subject to map, chain, and emit on and on for as many
   * functions you'd like to apply to it.
   */
  map: <B>(f: (x: A) => B) => IdentityMonad<B>

  inspect: () => string
}

interface IdentityFactory {
  <A>(x: A): IdentityMonad<A>
}

Collapse
 
rgeraldporter profile image
Rob Porter

This is great! 👍

Some comments have been hidden by the post's author - find out more