Skip to content

Instantly share code, notes, and snippets.

Nikolaos Maroulis nyo16

View GitHub Profile
View doctest_example.ex
defmodule MyApp.Hello do
@moduledoc """
This is the Hello module.
@doc """
Says hello to the given `name`.
Returns `:ok`.
View pmap.ex
def pmap(collection, func) do
|> -> func.(&1) end)))
nyo16 / pipe_example.ex
Last active Dec 6, 2018
Example pipe operator
View pipe_example.ex
def registration_changeset(model, params) do
|> 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?()
nyo16 / example.ex
Last active Dec 15, 2018
example in elixir
View example.ex
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}
You can’t perform that action at this time.