Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save evaporei/c16c1c1d966cf661346c34755b038a13 to your computer and use it in GitHub Desktop.

Select an option

Save evaporei/c16c1c1d966cf661346c34755b038a13 to your computer and use it in GitHub Desktop.
Category Theory - Functor Container Implementation
class Container<T> implements Functor<T> {
private value: T
constructor(value: T) {
this.value = value
}
fmap<U>(f: (a: T) => U): Functor<U> {
return new Container(f(this.value))
}
}
console.log(
'map integer container to string container:',
new Container(5).fmap((a) => String(a))
) // Container { value: "5" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment