[erlang-questions] Deputy: Type Conversion and Validation

Tom Burdick <>
Tue Apr 3 23:30:50 CEST 2012


I like the idea of making true/false synonymous with ok/false. I'm not
sure wrapping the fun handler with a try/catch clause is the right
thing to do though, in that case I believe it should be left as a
programming error.

I fixed the readme to reflect your comments, though I have not
bothered to actually test whats in the readme which is horrible I
know!

Maybe later this week I'll do both! Thank you for the comments.

Tom


On Tue, Apr 3, 2012 at 1:37 PM, Ladislav Lenart <> wrote:
> 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