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

kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
arkgil
Hi all! I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 18262 141
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Sub Categories:

We're in Beta

About us Mission Statement