Skip to content

Instantly share code, notes, and snippets.

@danielberkompas
Created October 20, 2015 14:20
Show Gist options
  • Save danielberkompas/52216db76d764a68dfa3 to your computer and use it in GitHub Desktop.
Save danielberkompas/52216db76d764a68dfa3 to your computer and use it in GitHub Desktop.
defmodule Pipeline do
defmacro __using__(_) do
quote do
import Kernel, except: [~>>: 2]
import Pipeline
end
end
defmacro lhs ~>> rhs do
quote do
case unquote(lhs) do
{:ok, value} -> value |> unquote(rhs)
other -> other
end
end
end
end
@CrowdHailer
Copy link

Why have you imported kernal and excepted ~>>. Is that just good form in case ~>> arrives in kernal in the future

@danielberkompas
Copy link
Author

Yeah. It isn't really necessary, though.

@CrowdHailer
Copy link

https://github.com/CrowdHailer/OK

Though a bit more work is needed to make it work with named function properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment