For the basic types you can you a when guard in the function clauses (or case clauses):<br><br>my_magic(#user{password=PW}) when is_binary(PW) -> ...<br><br>But that is probably not enough for you.<br><br>Cheers,<br>Torben<br>
<br><div class="gmail_quote">On Wed, Jul 13, 2011 at 01:26, Tristan Sloughter <span dir="ltr"><<a href="mailto:tristan.sloughter@gmail.com">tristan.sloughter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I'm pretty sure this isn't possible but I wanted to be sure before working around the lack of it.<div><br></div><div>if I have a type and record like:</div><div><br></div><div>-type password() :: binary().</div><div>
<br></div><div>-record(user, {username :: binary(),</div><div> password :: password()}. </div><div><br></div><div>At run time there is no way to tell a field is suppose to be of some type during runtime, right? </div>
<div><br></div><div>Basically I'd like to be able to have generic or generated create functions for records that may have to modify arguments (like a password has to be encrypted from the string provided) when creating the record. So the create function would pass each field, its value and its type to a transform function that matches on type and returns the appropriately modified value.</div>
<div><br></div><div>Any ideas on how to do this with type definitions or do I need to use tuples and an atom like {Type, Value} for the value of every field to achieve this?</div><div><br></div><div>Thanks,</div><div>Tristan</div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.linkedin.com/in/torbenhoffmann">http://www.linkedin.com/in/torbenhoffmann</a><br>