Classic Elixir Bug

Data in Elixir is immutable. This can lead to some subtle bugs.

Here is the example Ecto.Multi sample

defmodule PasswordManager do
  alias Ecto.Multi

  def reset(account, params) do
    Multi.new()
    |> Multi.update(:account, Account.password_reset_changeset(account, params))
    |> Multi.insert(:log, Log.password_reset_changeset(account, params))
    |> Multi.delete_all(:sessions, Ecto.assoc(account, :sessions))
  end
end

This could be rewritten as

defmodule PasswordManager do
  alias Ecto.Multi

  def reset(account, params) do
    multi = Multi.new()
    multi = Multi.update(multi, :account, Account.password_reset_changeset(account, params))
    multi = Multi.insert(multi, :log, Log.password_reset_changeset(account, params))
    multi = Multi.delete_all(:sessions, Ecto.assoc(account, :sessions))
  end
end

Forget to capture the multi at any step and you will lose the specific change from the batch.

This is insidious when moving from the first to the second to add a calculated value or when the function you are adapting only uses one multi

Wheel of Time season 2

After watching season 1 of wheel of time I started reading the books. Currently I am on book 13 of 14. This article is trying to be spolier free.

The TV adaption was always going to differ from the books. We are not going to get 14 seasons with all of the characters

Season 1 did a good job of introducing the world, and managed to introduce some characters earlier than we would otherwise have met them.

Starting the characters off a little older than the books returns to the authors intent, before being asked by his publisher to make them younger.

Critical numbers have been reduced and there are 8 Forsaken and it only takes 8 to still someone – these required 13 in the books.

There is a slight flaw in timing in the new episodes. Perrin is with a group tracking Pendan Fain from the end of the previous season yet the group in the White Tower seem to have been there longer. This could just be a syncronisation issue with his letter being written and received some time later.

Several of the characters are in different places to the book. Rand and Matt need to be with Perrin. Matt could join the girls on their trip to the coast later on. Not sure how Rand will make the journey.

An interesting note on the opening catchup – all characters that were focussed on will be important later on.