Comment

Comment by pg_bot

The following code could be written much better by using the cond operator.

    with {:is_email, true} <- {:is_email, is_email_address?(email)},
         {:is_available, true} <- {:is_available, EmailAddresses.is_available(email)} do
      ...
    else
      {:is_email, false} ->
        {:error, :bad_request}

      {:is_available, false} ->
        {:error, :conflict}
    end

    cond do 
      !email_address?(email) -> {:error, :bad_request}
      !EmailAddresses.available?(email) -> {:error, :conflict}
      true -> {:ok, email}
    end
This gets rid of unnecessary duplication, and I think is easier to understand.
parent pg_bot 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton