[erlang-questions] [ANN] sheriff 0.2: parse transform for type-based data validation

Loïc Hoguin essen@REDACTED
Mon Feb 13 11:52:18 CET 2012


We just released the first beta version of the sheriff parse transform. 
It allows you to validate data against types defined through the Erlang 
type system.

Sheriff allows you to write this:

   -type colors() :: blue | red | green | yellow.

   paint(Color, Object) ->
       case sheriff:check(Color, colors) of
           true ->
               do_paint(Color, Object);
           false ->
               {error, badarg}

In this example, sheriff:check/2 will check that Color is of type 
colors(), meaning it is one of 'blue', 'red', 'green' or 'yellow'.

This allows you to quickly and efficiently write validation code for 
unsafe external data without having to repeat yourself too much.

Sheriff can be found here along with extended usage instructions:

It's still in beta and has not been used in production yet, so feel free 
to open tickets on github if you find bugs or don't understand something.

Finally, I want to thank my students from last summer William Dang and 
Hamza Mahmood for doing the awesome initial work and research that led 
to this release. Thanks!

Loïc Hoguin
Erlang Cowboy
Nine Nines

More information about the erlang-questions mailing list