opus
opus copied to clipboard
Add an accessor pattern
I find often times I'm just folding a map, and most of the code ends up just being getting a key out of the map and then passing it to some validation/execution function
Current behavior
defmodule MyOpus do
use Opus.Pipeline
check :valid_email?
def valid_email?(%{email: email}) when is_binary(email) do
MyValidator.valid_email?(email)
end
end
Useful/Dry behavior
defmodule MyOpus do
use Opus.Pipeline
import MyValidator, only: [valid_email?: 1]
# some accessor/getter/lens syntax
check :valid_email?, in: :email
# or
check :valid_email?, get_in: [:email]
# or
check {:email, :valid_email?}
end
Hi @sitch, thank you for using Opus.
Have you tried?
defmodule MyOpus do
use Opus.Pipeline
import MyValidator, only: [valid_email?: 1]
check :valid_email?, with: &valid_email?(&1.email)
end
Yes of course, but my general use case is:
- Pass initial context as a map
- Run a step
- if it returns
{:ok, map}then merge it into the current context
So what ends up happening is:
Map.mergeceremony:oktuple ceremony- extracting key-values to pass to a function like that
valid_email?