Monthly Archives: June 2018

Data massaging in pipes with anonymous functions

The pipe operator is great. So great, in fact, that sometimes you just want to keep that pipe juice flowing and feel bad about breaking it up just to massage data into the appropriate shape before continuing with a new … Continue reading

Posted in Elixir, Pattern snippets | Comments Off on Data massaging in pipes with anonymous functions

Finer control in `with` failed matches

Elixir gives us the with┬áconstruct to combine matching clauses, which is very handy as programs frequently to perform an operation only if/when a set of preconditions is met. Let’s say we want to charge a product to a credit card: … Continue reading

Posted in Elixir, Pattern snippets | Comments Off on Finer control in `with` failed matches

Pattern matching in function heads: don’t go overboard

Elixir’s pattern matching is great, but make sure it’s not reducing your code’s readability. In particular, just because you can match all the variables you’ll need from within the function’s head doesn’t mean you should. Take this code: def handle_call(:checkout, … Continue reading

Posted in Elixir, Pattern snippets | Comments Off on Pattern matching in function heads: don’t go overboard