Bill Burcham
07/31/2019, 2:48 PMtypealias
didn’t support a recursive definition so I couldn’t do:
typealias State = (pushes: ReceiveChannel<Unit>, coins: ReceiveChannel<Unit>) -> State
So I had to resort to defining State
as a @FunctionalInterface
meh.
With some liberal casts, this compiles but it fails at runtime (see comment above line 59):
https://gist.github.com/Bill/b9cbfdb1d6fbba42258ee0a6fcee7240
Eschewing fun
and defining the states as `object`s works but that seems like a lot of extra ceremony:
https://gist.github.com/Bill/d5fa8c0290e49fccb90936745b29e86f
Any ideas here?dalexander
07/31/2019, 2:56 PMBill Burcham
07/31/2019, 3:02 PMdalexander
07/31/2019, 3:08 PMvar state = ::locked as State
the reason is a function is not part of state interface. Under the hood ::locked probably looks something like Function2<ReceiveChannel, ReceiveChannel, State>
which is not a State
. The only time Kotlin coerces function types to interfaces is when it's making calls to Java (which helps with Java 8 compatibility).Bill Burcham
07/31/2019, 3:13 PMsealed
class instead of a @FunctionalInterface
https://gist.github.com/Bill/d5fa8c0290e49fccb90936745b29e86fdalexander
07/31/2019, 3:15 PM