KerryAnnCoder@lemmy.blahaj.zonetoProgrammer Humor@programming.dev•What the f*ck is a monad
2·
1 year agoMaybe I’m not understanding it correctly, but Monads are data-structure objects whose methods return an data-structure object of the same type.
Like, (using Typescript):
interface IdentityMonad<T> {
map: ((fn: (v: T)) => T) => IdentityMonad<T>;
value: T
}
const Identity = <T>(value: T) => {
const map = (fn) => Identity(fn(initialValue));
return {
map, value
}
}
const square = (x) => x * x;
const twoId = Identity<number>(2);
console.log(twoId.value) //=> 2;
const sixtyFourId = twoId.map(square).map(square).map(square).map(square).map(square);
console.log(sixtyFourId.value) // => 64;
To be fair, those are British-style baked beans.
I was born and raised in the US (and have returned there) but spent the last 4 years living in London, and British beans in tomato sauce are very different from American baked beans in BBQ sauce. Both have their charms, but British beans are basically a breakfast food as main, American beans are a BBQ side-dish. Beans on Toast is a wonderful British breakfast, but Americans haven’t heard of it, and those who have might turn their nose up at it.
Very different cultures, and so much we can learn about multiculturalism for one can of baked beans - no, one picture of a can of baked beans.
So, yeah, I think it deserves and upvote.