Skip to content

Instantly share code, notes, and snippets.

View evaporei's full-sized avatar
🔮
spell caster

Eva Pace evaporei

🔮
spell caster
View GitHub Profile
@evaporei
evaporei / category-theory-monad-container-implementation.ts
Last active November 28, 2025 13:44
Category Theory - Monad Container Implementation
class Container<T> implements Monad<T> {
private value: T
constructor(value: T) {
this.value = value
}
bind<U>(f: (a: T) => Monad<U>): Monad<U> {
return f(this.value)
}
@evaporei
evaporei / category-theory-monads.ts
Created September 13, 2019 19:56
Category Theory - Monads
interface Monad<A> {
bind<B>(f: (a: A) => Monad<B>): Monad<B>
return(a: A): Monad<A>
}
@evaporei
evaporei / category-theory-functor-javascript-map.js
Created September 13, 2019 19:55
Category Theory - Functor JavaScript map
console.log('mapped list:', [1, 2, 3].map(x => x * 2)) // [2, 4, 6]
@evaporei
evaporei / category-theory-functor-container-implementation.ts
Created September 13, 2019 19:53
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))
}
@evaporei
evaporei / category-theory-functor-container.ts
Created September 13, 2019 19:52
Category Theory - Functor Container
class Container<T> {
private value: T
constructor(value: T) {
this.value = value
}
}
console.log('simple container:', new Container(5)) // Container { value: 5 }
@evaporei
evaporei / category-theory-functors.ts
Created September 13, 2019 19:51
Category Theory - Functors
interface Functor<A> {
fmap<B>(f: (a: A) => B): Functor<B>
}
@evaporei
evaporei / category-theory-monoid-strings-and-arrays.ts
Created September 13, 2019 19:50
Category Theory - Monoid Strings and Arrays
String.prototype.mappend = function (x: String): String {
return this + x
}
String.prototype.mempty = function (): String {
return ""
}
console.log(
'String mappend:',
@evaporei
evaporei / category-theory-monoid-integer-multiplication.ts
Created September 13, 2019 19:49
Category Theory - Monoid Integer Multiplication
Number.prototype.mappend = function (x: Number): Number {
return this * x
}
Number.prototype.mempty = function (): Number {
return 1
}
console.log('mappend:', Number(5).mappend(4)) // 20
console.log('mempty:', Number().mempty()) // 1
@evaporei
evaporei / category-theory-monoid-integer-sum.ts
Created September 13, 2019 19:48
Category Theory - Monoid Integer Sum
Number.prototype.mappend = function (x: Number): Number {
return this + x
}
Number.prototype.mempty = function (): Number {
return 0
}
console.log('mappend:', Number(5).mappend(4)) // 9
console.log('mempty:', Number().mempty()) // 0
@evaporei
evaporei / category-theory-monoids.ts
Created September 13, 2019 19:46
Category Theory - Monoids
interface Monoid<M> {
mappend(x: M): M // operação binária
mempty(): M // elemento neutro
}