MateuszNaKodach / SelfImprovement

This project has some sample code for my personal learning purpose. Things which I've learnead are collected as issues here: https://github.com/nowakprojects/SelfImprovement/issues
104 stars 17 forks source link

Read Occurrent Event Sourcing library documentation #4387

Open MateuszNaKodach opened 3 years ago

MateuszNaKodach commented 3 years ago

https://occurrent.org/documentation#command-composition

MateuszNaKodach commented 3 years ago

If you’re using Kotlin you can also make use of the andThen (infix) function for command composition (import org.occurrent.application.composition.command.andThen):

applicationService.execute(gameId,
    { events -> WordGuessingGame.startNewGame(events, gameId, wordToGuess) }
        andThen { events -> WordGuessingGame.makeGuess(events, guess) })

Events returned from WordGuessingGame.startNewGame(..) will be appended to the event stream when calling WordGuessingGame.makeGuess(..) and the new domain events returned by the two functions will be merged and written in an atomic fashion to the event store.