george.m
03/18/2024, 7:49 PMfun calculateDoubles(calcParams: Params) =
calcParams
.let { params ->
defrombulate(params.first, param.second)
.let { result ->
gaussianRoots(result)
.let { grtts ->
storeResult(params.first, params.second, result, grtts)
}
}
}
and do this instead:
fun calculateDoubles(calcParams: Params) =
// chained with let()
doLet(
{ calcParams },
{ params -> defrombulate(params.first, param.second) },
{ params, result -> gaussianRoots(result) },
{ params, result, grtts -> storeResult(params.first, params.second, result, grtts) }
)
Although in my code I have returns of types Result
or Either
.
I have tried looking on the Arrow docs but couldn't find an example of what I am looking for?
Could someone point me to some examples or documentation?
But I may be mistaken, and Comprehensions is not the way I should go about this.george.m
03/18/2024, 7:49 PMYoussef Shoaib [MOD]
03/18/2024, 8:01 PMfun calculateDoubles(calcParams: Params) = either {
val result = defrombulate(calcParams.first, calcParams.second).bind()
val grtts = gaussianRoots(result).bind()
storeResult(calcParams.first, calcParams.second, result, grtts)
}
Or it's even better if instead of returning Either
and Result
you instead use a Raise<MyErrorType>
receiver:
fun Raise<MyErrorType>.calculateDoubles(calcParams: Params) {
val result = defrombulate(calcParams.first, calcParams.second)
val grtts = gaussianRoots(result)
return storeResult(calcParams.first, calcParams.second, result, grtts)
}
george.m
03/18/2024, 8:09 PMbind()
, where we're waiting for the result as a val
then passing result in as an argument, where as in @pakoito’s examples the result is chained. and as mentioned,
I currently receive a Result
so I am `.fold()`'ing over the result and chaining manually and want to make that cleaner.
I'll look for a `either`/`bind()` exampleYoussef Shoaib [MOD]
03/18/2024, 8:10 PMEither
or Result
. bind
handles the unsuccessful case for you. It's like do-notation or for-comprehensions if you're familiar with thosegeorge.m
03/18/2024, 8:11 PMdo-notation or for-comprehensions if you're familiar with thoseI can't say I have had a lot of experience 😢
george.m
03/18/2024, 8:11 PMYoussef Shoaib [MOD]
03/18/2024, 8:12 PMgeorge.m
03/18/2024, 8:14 PMRaise<*>
Thanks for the guidance 👍Krisztian Balla
03/20/2024, 6:44 AMpakoito
03/25/2024, 5:29 PMpakoito
03/25/2024, 5:29 PMpakoito
03/25/2024, 5:30 PMpakoito
03/25/2024, 5:31 PMgeorge.m
04/08/2024, 5:52 PMeither
comprehensions, which have worked nicely for me so far
either {
val cool = doSomeThingCool().bind()
val cooler = makeItCooler(cool).bind()
}.fold(
ifRight = {},
ifLeft = {},
)
Whilst I am here though, if I am catching a throwable in the ifLeft
what is the recommendation to bubble that up to Crashlytics or similar?pakoito
04/09/2024, 9:26 AMpakoito
04/09/2024, 9:27 AMpakoito
04/09/2024, 9:28 AM