thanerian
06/04/2020, 12:34 PMstarke
06/04/2020, 10:18 PMOption<T>
properties
fun example() {
val maybeFoo: Option<DateTime>
val maybeBar: Option<DateTime>
// nested fold feels gross
val isFooAfterBar: Boolean = maybeFoo.fold(
ifEmpty = { false },
ifSome = { foo ->
maybeBar.fold(
ifEmpty = { true },
ifSome = { bar -> foo.isAfter(bar) }
)
}
)
// slightly better? same underlying logic though
val isFooAfterBarAlt: Boolean = maybeFoo.map { foo ->
maybeBar.map { bar -> foo.isAfter(bar) }.getOrElse { true }
}.getOrElse { false }
}
this code works, but I feel like there’s probably a better solution rather than nesting fold
🤔
the logic is basically:
if maybeFoo
is none()
, return false
if maybeFoo
is some()
and maybeBar
is none()
, return true
if maybeFoo
is some()
and maybeBar
is some()
, return foo > bar
any advice would be greatly appreciated! thankspakoito
06/04/2020, 11:16 PMpakoito
06/04/2020, 11:16 PMpakoito
06/04/2020, 11:17 PMifthis clause is the one that makes the logic not fit something likeismaybeFoo
andsome()
ismaybeBar
, return truenone()
Option.applicative().map
pakoito
06/04/2020, 11:17 PMfoo > bar
, then map would have worked 😄starke
06/04/2020, 11:18 PMjulian
06/04/2020, 11:39 PMSimple Dependency Management in Kotlin
gives a 404 on Github. Would anyone happen to have a different URL for the code?pakoito
06/04/2020, 11:41 PMraulraja
06/04/2020, 11:51 PMXuc Xiem
06/06/2020, 4:34 PMEither.catch
is used? I cannot find it.pakoito
06/06/2020, 6:40 PMpakoito
06/06/2020, 6:41 PMsuspend
pakoito
06/06/2020, 6:41 PMraulraja
06/09/2020, 10:56 PMtim
06/10/2020, 12:39 PMList<Option<String>>
and I want to return List<String>
i.e. filter every None. Any tips?
Ahh filterMap got it!pakoito
06/10/2020, 12:46 PMtim
06/10/2020, 12:52 PMtim
06/10/2020, 12:53 PMJanusz
06/10/2020, 1:41 PMio.arrow-kt:arrow-integration-retrofit-adapter:0.10.4
to my dependencies.
Is there a way to create an issue or pull request to improve that page?pakoito
06/10/2020, 1:43 PMpakoito
06/10/2020, 1:44 PMJanusz
06/10/2020, 2:52 PMcall.runAsync(IO.async())
Android studio tricked me into using fun <A> async(k: IOProc<A>): IO<A> = .....
From the IO class instead of the one from the IOAsync extensions file.Janusz
06/10/2020, 2:54 PMpakoito
06/10/2020, 2:59 PMpakoito
06/10/2020, 2:59 PMJanusz
06/10/2020, 3:16 PMpakoito
06/10/2020, 3:17 PMJanusz
06/10/2020, 3:17 PMCLOVIS
06/10/2020, 3:41 PMfun prepareLunchOption(): Option<Salad> =
fx.monad {
val lettuce = takeFoodFromRefrigerator().bind()
val knife = getKnife().bind()
val salad = prepare(knife, lettuce).bind()
salad
}
and
fun prepareLunchOption(): Option<Salad> =
Option.fx {
val (lettuce) = takeFoodFromRefrigerator()
val (knife) = getKnife()
val (salad) = prepare(knife, lettuce)
salad
}