this post was submitted on 02 Jul 2023
164 points (100.0% liked)

Programmer Humor

421 readers
19 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] sukhmel@programming.dev 5 points 1 year ago (1 children)

IIRC monoid also requires you to have zero, so that an initial value is known for any repetitive operation. In case of an array that'd be an empty one, in case of promise that'd be doing nothing, I guess.

[–] navigatron 1 points 1 year ago

Indeed, the identity element. I can’t remember if it’s required or just a nice to have - I’m leaning in agreement towards required.

Zero for integers, the empty string, an empty array, Promise.resolve(), an empty grocery list.

There’s a fantastic blog post out there, I can’t recall the name, that talks about modeling things with monoids - a list of package dependencies, for ex, is a monoid.

I believe there’s a similar identity concept for endofunctors, ie some identity function that does not modify their contents, ex ((a)=>a)