[erlang-questions] Callbacks with record name == module name
caio ariede
caio.ariede@REDACTED
Wed Dec 30 17:46:27 CET 2009
Or just apply
foo(Id) ->
{ok, V} = myapp_get_by_id(Id),
apply(element(1,V), foo, [V]).
Caio Ariede
http://caioariede.com/
On Wed, Dec 30, 2009 at 1:54 PM, Zoltan Lajos Kis <kiszl@REDACTED> wrote:
> You could abstract away the parts where you are getting into the guts.
>
> foo(Id) ->
> {ok, V} = myapp_get_by_id(Id),
> Class = class_of(V),
> Class:foo(V).
>
> class_of(V) ->
> element(1,V).
>
> You can also give parametrized modules a try. It has a more OO L&F.
>
> foo(Id) ->
> Obj = get_obj_by_id(Id),
> Obj:foo().
>
> get_obj_by_id(Id) ->
> {ok, V} = myapp_get_by_id(Id),
> Class = class_of(V),
> Class:new(V).
>
> Z.
>
> Taru Karttunen wrote:
>>
>> Hello
>>
>> Is it sensible to write code with callbacks for different "object"
>> types like:
>>
>> foo(Id) ->
>> {ok, V} = myapp_get_by_id(Id),
>> (element(1,V)):foo(V).
>>
>> Or is there a more idiomatic way of handling this?
>>
>> - Taru Karttunen
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
More information about the erlang-questions
mailing list