Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Witchcraft and Exceptional in the same module ? #81

Open
lkuty opened this issue Jun 9, 2020 · 0 comments
Open

How to use Witchcraft and Exceptional in the same module ? #81

lkuty opened this issue Jun 9, 2020 · 0 comments

Comments

@lkuty
Copy link

lkuty commented Jun 9, 2020

I use Elixir 1.10.2. My module has:

use Witchcraft, except: [>>>: 2]
use Exceptional

but at compilation time I get:

function >>>/2 imported from both Witchcraft.Chain and Exceptional.Raise, call is ambiguous
    expanding macro: Witchcraft.Monad.monad/2

If I try to do instead:

use Witchcraft, only: [monad: 2]
use Exceptional

Then I get:

:only and :except can only be given together to import when :only is either :functions or :macros

I am trying to add some error processing to my Timex usage which is not safe presently. I have copy pasted the code below to get an idea of my use case. It is used in a Phoenix web application.

    stream = monad Either.new() do
      date1 <- case Map.fetch(params, "date1") do
        {:ok, date1_s} -> case Date.from_iso8601(date1_s) do
          {:ok, date} -> date |> Timex.to_datetime(:local) |> Either.Right.new
          {:error, reason} -> Either.Left.new("error for date1: #{inspect(reason)}")
        end
        :error -> Timex.now(:local) |> Timex.beginning_of_day |> Either.Right.new
      end
      # ...    
      return HydroDB.Database.defaults(site, date1, date2, gens, newdefaults, regex)
    end
    case stream do
      %Either.Right{right: stream_} -> send_stream(conn, stream_, "text/xml")
      %Either.Left{left: error}     -> send_resp(conn, 422, error)
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant