mudasobwa
π°ππππππππ (Exvalibur) β Smart Validation In Elixir
Exvalibur is the generator for blazingly fast validators of maps based on sets of predefined rules.
Under the hood, it generates a module with many different clauses of the same valid?/1 function with explicitly hardcoded pattern matches and guards on the input.
Here is the blog post shedding a light on what goodness it provides and h)ow is it implemented β https://dev.to/mudasobwa/--smart-validation-in-elixir-4bcm
Most Liked
mudasobwa
True that, but I struggled to find a better name to be short and self-explanatory. OTOH, I do not want to miss the opportunity to return what was indeed validated on success.
Maybe I should go with validate/1 to return what valid?/1 currently returns and valid?/1 to return boolean.
mudasobwa
david_ex
For what itβs worth, hereβs the convention about trailing question marks and boolean return values: https://hexdocs.pm/elixir/master/naming-conventions.html#trailing-question-mark-foo
mudasobwa
Starting with v0.8.0 Exvalibur accepts module-based validatiors:
defmodule Validator do
use Exvalibur, rules: [
%{
matches: %{currency_pair: <<"EUR", _ :: binary>>},
conditions: %{foo: %{min: 0, max: 100}},
guards: %{num: num > 0 and num < 100}}]
end
Validator.valid?(%{currency_pair: "EURUSD", foo: 50, num: 50})
#β {:ok, %{currency_pair: "EURUSD", foo: 50, num: 50}}
Validator.valid?(%{currency_pair: "USDEUR", foo: 50, num: 50})
#β :error
fuelen
I tend to think that there is a convention that functions with ? should return boolean type








