OOlib
OOlib copied to clipboard
`pick` does not work with `isInstanceOf`, when should (protocol == protocol)
import oolib
protocol Session:
proc connect()
proc disconnect()
protocol Streamable:
proc read(): string
proc write(data: string)
class Player impl (Session, Streamable):
proc connect() = echo "Player connected"
proc disconnect() = echo "Player disconnected"
proc read(): string = echo "Reading"
proc write(data: string) = echo "Writing"
proc resolve(self: Session) = echo self
let player = Player.new()
let playerProtocol = player.toProtocol()
resolve(playerProtocol.pick(Session))
let session = playerProtocol.pick(Session)
echo session.isInstanceOf(Session) ## false
echo session.isInstanceOf(Streamable) ## false
echo session.isInstanceOf(Player) ## false
To be honest I haven't decided how to implement isInstanceOf on protocol itself yet, because It's obvious that an instance of a certain protocol like session has the structure of Session type(though the same can be said for the relation between player and Player) and I don't know if there's a case where an instance of protocol need type-checking.