DaAnalyst
Implementing an (aspect) Protocol for modules implementing another Protocol
On several occasions I’ve had this need to implement a Protocol for all modules implementing one other particular Protocol e.g.
defimpl Viewable, for: Doable do
..
end
One could argue to merge the two protocols into one, but in those few particular cases it is not applicable over the separation of concerns, as the protocols themselves are defined in two completely separate parts of the application and their respective implementations are more like two different behavioral aspects than just the protocols (i.e. they are not just wrapping the function calls to the structure modules but providing some additional behavior as well).
Any thoughts?
Most Liked
benwilson512
You can sort of achieve this by having the Viewable protocol fallback_to_any and then in the any clause check to see if the item provided implements Doable.








