Nowak
12/07/2020, 3:24 PMval chainReactions: ChainReactions = mutableMapOf()
typealias ChainReactions = MutableMap<DomainEvent, DomainEvent>
rocketraman
12/07/2020, 3:34 PMreaction
is a lambda, but you seem to be treating it as a DomainEvent
? Not sure what you're trying to do here...rocketraman
12/07/2020, 3:35 PMreaction(event)
will solve your compile error.bartvh
12/07/2020, 5:08 PM(T: D) -> E
is not assignable to (D) -> E
because, assuming that another type Y
extends D
, a function of type (D) -> E
must accept a Y
argument, which (T) -> E
does not.bartvh
12/07/2020, 5:11 PMchainReactions[event] = { d ->
@Suppress("UNCHECKED_CAST")
reaction(d as T)
}
assuming that chainReactions
is encapsulated enough that the cast is guaranteed to be safe at runtime.bartvh
12/07/2020, 5:15 PME
parameter altogether, and replace references to it simply with DomainEvent
.bartvh
12/07/2020, 5:16 PMinline
and using reified
?bartvh
12/07/2020, 5:19 PMNowak
12/09/2020, 10:03 AMfun <T : DomainEvent> chainReaction(event: T, reaction: (T) -> DomainEvent) = apply {
this.chainReactions[event] = reaction(event)
}