Open dreid opened 10 years ago
Well, besides that you're mutating immutable structures all over the place ;-)
I'm not sure about pattern matching data structures, this builds towards how do you pattern match against user defined types, and I don't know what that API looks like.
In Erlang it often ends up being useful to model the state invariants as pattern matches of expectations of complex types.
For instance, an IRC chat room that is empty the first user to join it becomes the operator, if it is ever empty again the new first user to join it becomes the operator.
You could explicitly track the empty state, but it is much easier to have the function that decides if it should op the joining user to simply dispatch on a match of the user list.
In bagel I'd expect this to look something like…