Last active
April 2, 2024 05:23
-
-
Save Krever/e82a99ef24b37ef4d9e4fe574d6ed04b to your computer and use it in GitHub Desktop.
Revisions
-
Krever revised this gist
Apr 2, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ trait WorkflowContext { } object WithdrawalContext extends WorkflowContext { type Event = WithdrawalEvent type State = WithdrawalState } -
Krever created this gist
Mar 31, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ // This is a very minimal example showcasing how we can levarage type members to capture fixed types without the need // to introduce more type parameters trait WorkflowContext { type State type Event // operation that transforms In into Out, while guaranteeing the output is a substate os State sealed trait WIO[Err, In, Out <: State] object WIO { // example variant where IO is guarded with an event, IO is not run during recovery. // event is guaranteed to be subtype of Event case class HandleIO[Err, In, Out <: State, Evt <: Event](runIO: In => IO[Evt], handleEvent: Evt => Either[Err, Out]) extends WIO[Err, In, Out] } } object WithdrawalContext { type Event = WithdrawalEvent type State = WithdrawalState } class WihdrawalWorkflow(service: WithdrawalService) { // output type is specific to WithdrawalContext // runing this workflow requires persistance for WithdrawalEvent // at any point of time, we can get a state of the workflow which will be of type WitdrawalState def workflow: WidrawalContext.WIO[Nothing, Unit, WithdrawalState.Complete] = WIO.RunIO( _ => service.doSth().as(WithdrawalEvent.SthDone), sthDone => WiithdrawalState.Completed() ) }