-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More user friendly Configuration API #8
base: master
Are you sure you want to change the base?
Conversation
The compiler errors from Configuration.from are confusing enough when working with the 4 different function handles without the additional confounder of there being four different versions of the from method which take different arguments. This should help cut down on the confusion.
Changes an error that looks like this: ``` Error:(28, 27) Kotlin: Type inference failed: Cannot infer type parameter UpdateEvt in inline fun <reified CreationCmd : CreationCommand, CreationEvt : CreationEvent, CmdErr : CommandError, reified UpdateCmd : UpdateCommand, UpdateEvt : UpdateEvent, reified Agg : Aggregate> from(noinline create: (CreationCmd) -> Either<CmdErr, CreationEvt>, noinline update: Agg.(UpdateCmd) -> Either<CmdErr, List<UpdateEvt>>, noinline created: (CreationEvt) -> Agg, noinline updated: Agg.(UpdateEvt) -> Agg = ..., noinline aggregateType: Agg.() -> String = ...): Configuration<CreationCmd, CreationEvt, CmdErr, UpdateCmd, UpdateEvt, Agg> None of the following substitutions ((PizzaCreationCommand) -> Either<PizzaError, PizzaCreated>,Aggregate.(PizzaUpdateCommand) -> Either<PizzaError, List<PizzaUpdateEvent>>,(PizzaCreated) -> Aggregate,Aggregate.(PizzaUpdateEvent) -> Aggregate,Aggregate.() -> String) ((PizzaCreationCommand) -> Either<PizzaError, PizzaCreated>,Aggregate.(PizzaUpdateCommand) -> Either<PizzaError, List<UpdateEvent>>,(PizzaCreated) -> Aggregate,Aggregate.(UpdateEvent) -> Aggregate,Aggregate.() -> String) ((PizzaCreationCommand) -> Either<PizzaError, PizzaCreated>,Aggregate.(PizzaUpdateCommand) -> Either<PizzaError, List<@ParameterName PizzaUpdateCommand>>,(PizzaCreated) -> Aggregate,Aggregate.(PizzaUpdateCommand) -> Aggregate,Aggregate.() -> String) can be applied to (KFunction1<@ParameterName PizzaCreationCommand, Either<PizzaError, PizzaCreated>>,KFunction2<PizzaAggregate, @ParameterName PizzaUpdateCommand, Either<PizzaError, List<PizzaUpdateEvent>>>,KFunction1<@ParameterName PizzaCreationEvent, PizzaAggregate>,KFunction2<PizzaAggregate, @ParameterName PizzaUpdateCommand, Either<PizzaError, List<PizzaUpdateEvent>>>) ``` into ``` Error:(26, 30) Kotlin: Type mismatch: inferred type is KFunction2<PizzaAggregate, @ParameterName PizzaUpdateCommand, Either<PizzaError, List<PizzaUpdateEvent>>> but PizzaAggregate.(PizzaUpdateEvent) -> PizzaAggregate was expected ```
Frustratingly these have to be public for reified types to work, and since the reified types are super valuable I'm just doing this to make it obvious to the caller not to use them.
89c1dbe
to
73bbeda
Compare
I'm wondering whether we should abandon the configuration building options, and just insist on using (aside: coming from a Python background here – I get very frustrated by things such as method aliases in Ruby! Now we have to choose one of several functionally identical ways to do a standard thing, and it may not look like what other devs chose in the same codebase. And now we have to run Rubocop to tell us to use one over the other!). In Kotlin, i think the The other way to be opinionated would be avoid the Another aside: I spent a bit of time this morning trying to write a nice fleshed out DSL (just to see if I could) based on your work here, so you could do something like:
but I couldn't get the type inference to work unfortunately, so it ended up being just as verbose as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty reasonable. Do you still need a detailed review on this @williamboxhall ?
Ah thanks for the look @admackin! This has definitely gotten stale so I reckon hold off on a detailed review for now and I might rebase this and go over it again when I have a chance. |
This is a WIP and does a few things and is best reviewed commit by commit
Configuration.from
methods to be more specific to avoid the method overloading which makes compiler messages more convoluted.Configuration
out into it's own class since it's getting complicatedCalling the builder looks like this:
and changes an error that looks like this:
into