PacketAbstraction

trait PacketAbstraction[Packet, WorldView, +Cmd]

An abstraction of packet data within a SightedClient. This is a functional interface of the form Packet => Option[WorldView => (WorldView, Cmd)].

Packet is the (super-)type of packets to abstract away, WorldView is SightedClient's view of the world corresponding to an abstraction and Cmd is a datatype that describes an effect to cause whenever a view modification takes place.

A "view modification" is a function of the form WorldView => (WorldView, Cmd). It arises as a result of receiving packets, and is a function from the old WorldView to a pair of new WorldView and an effect Cmd.

This functional object receives a packet and judges if the packet should invoke a view modification. If so, it returns a Some[WorldView => (WorldView, Cmd)] and None otherwise.

Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def viewUpdate(packet: Packet): Option[WorldView => (WorldView, Cmd)]

A function that receives a packet and judges if the packet should invoke a view modification.

A function that receives a packet and judges if the packet should invoke a view modification.

Concrete methods

final
def defocus[BroaderView](lens: Lens[BroaderView, WorldView]): PacketAbstraction[Packet, BroaderView, Cmd]

"Defocus" this abstraction to deal with a larger view datatype BroaderView that contains more information than WorldView.

"Defocus" this abstraction to deal with a larger view datatype BroaderView that contains more information than WorldView.

final
def keepTrackOfViewChanges: PacketAbstraction[Packet, NonEmptyList[WorldView], Cmd]

Construct an abstraction that keeps track of all past views. This may be better suited for debugging purposes.

Construct an abstraction that keeps track of all past views. This may be better suited for debugging purposes.

final
def liftCmd[F[_], C2 >: Cmd](using F: Applicative[F]): PacketAbstraction[Packet, WorldView, F[C2]]

Lift the Cmd type to F[Cmd] for some applicative type F.

Lift the Cmd type to F[Cmd] for some applicative type F.

final
def liftCmdCovariant[F[_]](using F: Applicative[F]): PacketAbstraction[Packet, WorldView, F[Cmd]]

Lift the Cmd type to F[Cmd] for some covariant applicative type F.

Lift the Cmd type to F[Cmd] for some covariant applicative type F.

final
def mapCmd[C2](f: Cmd => C2): PacketAbstraction[Packet, WorldView, C2]

Obtain a new PacketAbstraction by mapping the output Cmd.

Obtain a new PacketAbstraction by mapping the output Cmd.

final
def orElseAbstract[C2 >: Cmd](another: PacketAbstraction[Packet, WorldView, C2]): PacketAbstraction[Packet, WorldView, C2]

Combine this abstraction with another. The obtained abstraction will attempt to update the view using another if this object rejects to update the view.

Combine this abstraction with another. The obtained abstraction will attempt to update the view using another if this object rejects to update the view.

final
def thenAbstract[P, C2](another: PacketAbstraction[P, WorldView, C2])(using ng: NotGiven[P <:< Packet], ge: GivenEither[Typeable[Packet], Packet =:= Nothing]): PacketAbstraction[Packet | P, WorldView, C2 | Cmd]

Combine this with another abstraction that deals with a packet type P that is not a subtype of Packet. The result of a view update for a packet p of type Packet | P will be:

Combine this with another abstraction that deals with a packet type P that is not a subtype of Packet. The result of a view update for a packet p of type Packet | P will be:

  • if p: Packet, then this.viewUpdate(p)
  • if otherwise p: P, then another.viewUpdate(p)
final
def widenPackets[WPacket](using TypeTest[WPacket, Packet]): PacketAbstraction[WPacket, WorldView, Cmd]

Widen the packet type to a type WPacket whose values can be narrowed down to Packet.

Widen the packet type to a type WPacket whose values can be narrowed down to Packet.