This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Hello do | |
@moduledoc """ | |
This is the Hello module. | |
""" | |
@doc """ | |
Says hello to the given `name`. | |
Returns `:ok`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pmap(collection, func) do | |
collection | |
|> Enum.map(&(Task.async(fn -> func.(&1) end))) | |
|> Enum.map(&Task.await/1) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_active(nil), do: {:error, :not_found} | |
def is_active(%User{accounts: []}), do: {:error, :no_active_account} | |
def is_active(%User{accounts: accounts} = user), do: {:ok, user} | |
def is_active(_), do: {:error, :something_happend} |