[erlang-questions] Deputy: Type Conversion and Validation

Ladislav Lenart <>
Tue Apr 3 20:37:06 CEST 2012


Hello.

Nice little work :-)

Just a few notes:
* Documentation typo in Proplist Usage - Rules is defined but later
   RuleSet is used.
* Documentation about Addon Type Conversion seems unfinished.
* Why the advanced API needs to be exported at all?
* I would modify interface of convert/2 to either:
   * return the result value directly | raise an error,
   * use tagged tuples {ok, Value} | error.
* I think check/3 returns errors in reversed order when stop is used.
* I would suggest to extend (both) {func,...} to

       check_rule(Value, {func, Fun}) when is_function(Fun, 1) ->
           try
               Fun(Value)
           catch
               _:_ ->
                   error
           end;

   This will enable you to write shorter rules. Instead of

       Test = fun (Value) ->
           case Value > 1 andalso Value < 10 of
               true -> ok;
               false -> error
           end
       end

   you will be able to write

       Test = fun (Value) -> true = Value > 1 andalso Value < 10, ok end

   or (in a different style)

       Test = fun (Value) ->
           true = Value > 1,
           true = Value < 10,
           ok
       end

   and if you allow true as synonym for ok and false as synonym for error,
   you can omit ok at the end.


HTH,

Ladislav Lenart


On 3.4.2012 19:12, Tom Burdick wrote:
> After not finding a validation/conversion library I felt worked well
> for what I wanted (REST interface) I made my own.
>
> Would greatly appreciate any feedback!
>
> http://github.com/treetopllc/deputy
>
> Thanks!
>
> Tom
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>





More information about the erlang-questions mailing list