Hello Andrea!

Imagine, as a library author, that a library module can somehow receive a 
module from your application to call functions on.

E.g. `use LibraryModule, yourModule: Foo`

`LibraryModule` expect to receive in its `:yourModule` option a module 
implementing a certain behaviour. `Foo` is given and the library code wants 
to raise an error if the given module doesn't implement the expected 
behaviour.

Actually I thought, that should be pretty common. So I checked in the 
dependencies containing large amount of code and configs such as Phoenix, 
Ecto, Absinthe, and so on, and guess what, this pattern is almost not 
used...

I still found this:
https://hexdocs.pm/ecto/Mix.Ecto.html#ensure_implements/3


On Sunday, May 17, 2020 at 5:15:08 PM UTC+2, Andrea Leopardi wrote:
>
> Hey Thomas,
>
> do you have a specific use case in mind to check that a module implements 
> a behaviour? The fact that you can do this today by getting the module 
> attributes makes me lean towards not adding this to the standard library, 
> but I'm curious as to that's the use case you're thinking of :)
>
> Andrea
>
> On Sun, May 17, 2020 at 10:41 AM Thomas J. <[email protected] 
> <javascript:>> wrote:
>
>> Hello,
>>
>> What do you think about adding `implements?/2`?
>>
>> It accepts two module names as parameters, and it checks if the first 
>> parameter implements the behaviour passed as the second parameter.
>>
>> It would execute something like:
>>
>> `Enum.member?(Foo.module_info[:attributes][:behaviour], Bar)`
>>
>> Only problem I see is that a module can somehow implement a behaviour 
>> without wriring the @behaviour statement. But that could be a documented 
>> limitation.
>>
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/12b5fbff-7460-44c1-81c1-b6710949738e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/12b5fbff-7460-44c1-81c1-b6710949738e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/ce4d589d-5288-4887-9340-4408f2d50e63%40googlegroups.com.

Reply via email to