Hey folks, how are you? I'm experimenting gleam for the first time in a personal project. I'm trying to build a digital version of a very complex tabletop game. I thought that since it is a game with turns etc, and it has very complex rules that various things happening may trigger some effect, using event sourcing and CQRS would be a good idea, but I'm currently struggling implementing it with generic custom types.
I have a type Command defined as:
pub type Command(command_data) {
Command(issued_at: Time, issuer: String, data: command_data)
}
And an Event type defined as:
pub type Event(event_payload) {
Event(id: String, data: event_payload, source: EventSource, created_at: Time)
}
For the command_data type I have the GameCommand type, defined as:
pub type GameCommand {
CreateGame(players: List(Player), map: Map)
}
So I can generate a structure like:
Command(issuer: "system", issued_at: birl.now(), data: CreateGame(players: [], map: map))
I'm trying to use actors from gleam_otp to create a pub-sub system for my event store, so when I try to process a new command:
fn handle_commands(
command: Command(d),
events: List(Event(p)),
) -> actor.Next(Command(d), List(Event(p))) {
case command {
Command(data: CreateGame(players, map), issuer: issuer, ..) -> GameCreated(players: players, map: map) |> list.wrap() |> list.append() |> actor.continue
But I'm having the following error (attachment).
Must I have to define each possible value of d as alternative types? Shouldn't I be able to just make the type generic?