groostav
10/04/2016, 7:01 PMMulticastingDelegate class that effectively extends List<DelegateType> implements DelegateType, primarily so I could get the C#-familiar syntax
val(r) callbacks = MulticastingDelegate();
callbacks += { x -> whatever() }
but! If I use kotlins nice immutable & persistent collections interfaces (eg List and not MutableList), then when I write += I get the extension function on List type, which means plus returns a regular List, not a new MulticastingDelegate.
Thus I get a type error. To fix this type error with my types, I would need to override the += (and presumably -=) functions locally on my MulticastingDelegate type.
So my choices:
- override a mutable collection (such as LinkedList), then += hits the extension mutation operator plusAssign, and my original data structure is updated, rather than replaced. removing the type error.
- override += and -= operators myself (effectively, remove the benefits of extending List and implement my own collection), as mentioned above
- ditch the concept of a new type entirely, and simply write a operator fun List<DelegateType>.invoke(...) extension function.
That third option is pretty appealing to me.
Am I missing something? Any chance such a type can be added to Kotlin (or lib Funktional)?