Sorry another newb question. I've have several fun...
# arrow
t
Sorry another newb question. I've have several functions that are called serially and only return a concrete value if they fail ... i've tried representing them as Option<Failure> but I'm unsure how to construct the comprehension on None. Is there an easy way to do this, or should I be using Either? If Either, what type should I use on the Right (Unit?)?
b
huh that's a long
.getOrElse
chain
val result = optA.getOrElse(optB).getOrElse(optC).orElse("no failures")
, +/- some type matching
👍🏼 1
There wouldn't be a comprehension on None
t
👍 I had tried applicative.mapN, but I can now see that only fires when all inputs are Some/Right
I'll give the getOrElse chain a try 🙏
b
Full disclosure, I may have that method name wrong. 🙂
Usually it's something like 'getOrElse', but I can't remember for sure what it is on Option in Kotlin
t
thats cool i'll take a look shortly and should be able to figure it out from tehre
p
if you user Either it'll be easier because of the
swap
method
t
okay i'll give both a try and see what seems most coherent
b
ahh yeah, Either comprehension will stop on first failure then swap and maybe toOption
See, it's a good thing @pakoito knows what he's talking about
p
we had this issue on JS and Hack (PHP) where you couldn't build comprehensions for the null case
so you end up with awkward statements to make them work
in Kotlin the
:?
works, right?
it's
?let
and
:?
b
Fore sure ?.let. I think ?: as well but I'm less sure of that
I lose track between Scala Groovy Kotlin and Java
😄 2
If I delved into Clojure at least I wouldn't have trouble with remembering operators, just matching parens (((())))
p
billions and billions and billions of parens
❤️
(-> forms)
for the extra pain haahah
b
ugh that is SO wrong
TBH my biggest pain point is remembering the lambda syntax between the big 4
I usually fumble around in the IDE until the red squiggles disappear
and the type hints appear