jet / dotnet-templates

Example app and service templates `dotnet new -i Equinox.Templates; dotnet new eqx*/pro*` https://github.com/jet/equinox https://github.com/jet/FsCodec
https://github.com/jet/propulsion
Apache License 2.0
64 stars 16 forks source link

Demonstrate TransactWith impl pattern #113

Closed bartelink closed 2 years ago

bartelink commented 2 years ago

While there can be a place for a DRY let-bound helper in a type Service, in general it makes more sense to codify a specific Transact or Query pattern common within a particular category, domain or app as an extension method on Decider, rather than as a local helper.

cc @ahjohannessen

bartelink commented 2 years ago

For context, some other examples snipped from a codebase I'm working on:

      member x.TransactAsyncWithVersionAndPostState(decide, mapResult) =
        x.TransactEx((fun c -> decide c.Version c.State), fun r c -> mapResult r c.State)
     member x.TransactAsyncWithPostState(decide, mapResult) =
        x.TransactEx((fun c -> async { let! es = decide c.State in return (), es }), fun () c -> mapResult c.State)
     member x.TransactWithPostState(decide, mapResult) =
        x.TransactEx((fun c -> async { let es = decide c.State in return (), es }), fun () c -> mapResult c.State)
     member x.QueryWithVersion(projection) =
        x.QueryEx(fun c -> c.Version, projection c.State)