mudasobwa

mudasobwa

Creator of Cure

π•°π–π–›π–†π–‘π–Žπ–‡π–šπ–— (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

mudasobwa

Creator of Cure

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

mudasobwa

Creator of Cure

As I continue working on Exvalibur, I have implemented custom guards and pattern matching of values.

I just blogged about how I used custom sigils to allow quoted expressions in the rules.

david_ex

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

mudasobwa

Creator of Cure

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

fuelen

I tend to think that there is a convention that functions with ? should return boolean type

Where Next?

Popular in Libraries Top

marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run β€˜elixir’ comma...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

Sub Categories:

We're in Beta

About us Mission Statement