Category Archives: Elixir

PoolToy: A (toy) process pool manager in Elixir 1.6 (part 1.3)

Managing a single pool (continued) (This post is part of a series on writing a process pool manager in Elixir.) In the previous post, we managed to get our pool supervisor to start the pool manager. Now, our next objective … Continue reading

Posted in Elixir | Comments Off on PoolToy: A (toy) process pool manager in Elixir 1.6 (part 1.3)

PoolToy: A (toy) process pool manager in Elixir 1.6 (part 1.2)

Managing a single pool (continued) (This post is part of a series on writing a process pool manager in Elixir.) Continuing from the previous post, we’re working on having a single pool of processes that we can check out to … Continue reading

Posted in Elixir | Comments Off on PoolToy: A (toy) process pool manager in Elixir 1.6 (part 1.2)

PoolToy: A (toy) process pool manager in Elixir 1.6 (part 1.1)

A new project (This post is part of a series on writing a process pool manager in Elixir.) Without further ado, let’s get started with PoolToy: mix new pool_toy Pools will contain worker processes that will actually be doing the … Continue reading

Posted in Elixir | Comments Off on PoolToy: A (toy) process pool manager in Elixir 1.6 (part 1.1)

PoolToy: A (toy) process pool manager in Elixir 1.6

Contents This series of posts will guide you in writing an OTP application that will manage pools of processes. In particular, it will do so using features introduced in Elixir 1.6 such as the DynamicSupervisor and the Registry. There’s quite … Continue reading

Posted in Elixir | Comments Off on PoolToy: A (toy) process pool manager in Elixir 1.6

Data massaging in pipes with anonymous functions

This technique is obsolete since Elixir v.1.12, as it has introduced then/2 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 … 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

Keyword list reduction

Keyword lists are often used to provide optional values, which are then processed (for example to initialize the state). One really nice way to do so, is with a reduce pattern. I’ve never seen anyone bringing attention to it in … Continue reading

Posted in Elixir, Pattern snippets | Comments Off on Keyword list reduction