What is the way to chain methods with different signatures describing a business process? #2825
Replies: 3 comments
-
I posted this to Stackoverlow. |
Beta Was this translation helpful? Give feedback.
-
@Andras-Csanyi Where you are using Also, .flatMap(__ -> validateInput(context.getWhateverEntityInput(), context.getCorrelationId())) I am using |
Beta Was this translation helpful? Give feedback.
-
If you don't want to create a bunch of classes that represent transitional stages between your methods, you could simply use a |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I am new in the functional programming world, so please be gentle... :D And I believe my Java knowledge is a bit rusty too.
I have the following process I'd like to describe with chained methods returning
Either
.The process receives a context object containing a
WhateverInput
andcorrelationId
and processes these in the following steps:The
correlationId
is there to mark which process the operation belongs to if the process fails.What I tried is
map
andflatMap
, but both of them expects a function where the input is the Either's Right and an Either as a return value. However my method signatures look like below due to that I don't want to put the correlation id into a field.How to do this in a nice, best/good practices way? What I can think of is creating a
Context
object adding to it both theWhateverInput
andcorrelationId
and thisContext
will be theRight
side of theEither
and moving this object between methods. But, it feels a bit clunky, heavy.I study functional programming in both Java and C# in the same time and the example above can be done in C# using
Bind
and I am looking for an equivalent for that or the solution how theBind
, what it seems likemap
orflatMap
, can be done.Thanks the answers in advance.
Beta Was this translation helpful? Give feedback.
All reactions