[proposal] make all callbacks optional by specifying the behaviour module

44 views
Skip to first unread message

Hylke Alons

unread,
Sep 13, 2018, 10:04:08 AM9/13/18
to elixir-lang-core
Hello!

Sometimes I want to make all callbacks in a behaviour optional. Right now I need to specify everything manually.

My proposal would be something consistent to defoverridable, in which you can make all methods overridable by using the module. 

So instead of 
defmodule SomeBehaviour do
 
@callback x(a, b) :: boolean
 
@callback c(a, b) :: binary

 
@optional_callbacks x: 2, c: 2
end


defmodule SomeBehaviour do
 
@callback x(a, b) :: boolean
 
@callback c(a, b) :: binary

 
@optional_callbacks SomeBehaviour
end



Louis Pilfold

unread,
Sep 13, 2018, 12:25:50 PM9/13/18
to elixir-l...@googlegroups.com
Hey Hylke!

In the mean time you could parse the value contained in the @callback attribute and generate a list of all the functions :)

Cheers,
Louis

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9150632a-e2a1-46c8-b885-b3fd297a2cf4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hylke Alons

unread,
Sep 14, 2018, 6:13:46 AM9/14/18
to elixir-lang-core
Thanks for your reply Louis! 

What would that look like? 
Reply all
Reply to author
Forward
0 new messages