Hardcore Functional Architecture Patterns in JavaScript

## Brian Lonsdorf

Salesforce

### Check out a free preview of the full Hardcore Functional Architecture Patterns in JavaScript course

The "Homomorphisms & Monads" Lesson is part of the full, Hardcore Functional Architecture Patterns in JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Brian gives an example of a homomorphism. A homomorphism takes two elements and combines them then goes through a type transformation. At a high level, when combining a monoid operation and flattening two types, these types become monads.

Preview
Close

### Transcript from the "Homomorphisms & Monads" Lesson

[00:00:00]
>> The only point that I want you to take from this is there are properties, and that's why we we strive to do this stuff. We have associativity, we have identity. There's a thing called a homomorphism, where we can actually take a monoid in and do a type transformation to another monoid.

[00:00:17]
And the properties would still hold. And here's a just an example of a monoidal homomorphism. Where here we have a message. And then we're gonna parse that message from a string, and then we call MergeFrom. So it looks like what's happening here is, we can actually parse the message, and parse the other message and merge it.

[00:00:44]
Or we can combine the messages and then parse it, and both are monoids. And we're able to make decisions on making things more efficient. By first combining them and then doing the type transformation, or combining them all, or doing the type transformation first and then combining them. Okay, Cayley's Theorem is pretty great, but we're not gonna deal with it.

[00:01:07]
And monads are monoids in the category of endofunctors, you can think of chain as in nesting. So if I have a type within a type and I can flatten that type, that's a monoidal operation. We're combining them. So that's how hand wavy, kinda nutshell way, the monads are monoids.

### Learn Straight from the Experts Who Shape the Modern Web

• In-depth Courses