Instantly share code, notes, and snippets.

View pmap.ex
def pmap(collection, func) do
collection
|> Enum.map(&(Task.async(fn -> func.(&1) end)))
|> Enum.map(&Task.await/1)
end
View pipe_example.ex
def registration_changeset(model, params) do
model
|> cast(params, [:email, :password])
|> validate_required([:email, :password])
|> validate_format(:email, ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)
|> unique_constraint(:email)
|> validate_length(:password, min: 8)
|> update_password?()
end
View example.ex
def is_active(nil), do: {:error, :not_found}
def is_active(%User{active?: true} = user), do: {:ok, user}
def is_active(%User{active?: false}), do: {:error, :not_active}
def is_active(_), do: {:error, :something_happend}