starke
04/23/2019, 3:06 PMOption<Int>
values?marstran
04/23/2019, 3:07 PMstarke
04/23/2019, 3:08 PMvalue 1
+ value 2
< value 3
starke
04/23/2019, 3:08 PMstarke
04/23/2019, 3:10 PMmarstran
04/23/2019, 3:14 PMoption1.getOrElse { 0 } + option2.getOrElse { 0 } < 3
starke
04/23/2019, 3:15 PMstarke
04/23/2019, 3:15 PMAdrianRaFo
04/23/2019, 3:21 PMOption
binding
so
Option.fx().fx{
val value1 = !option1
val value2 = !option2
value1 + value2 < 3
}
That will return an`Option<Boolean>` so you can use it as you wantstarke
04/23/2019, 3:23 PMOption<Boolean>
is what I needsimon.vergauwen
04/23/2019, 3:24 PMraulraja
04/23/2019, 3:34 PMOption(1) + Option(1)
because we can summon the semigroup of Int automaticallyAdrianRaFo
04/23/2019, 3:35 PMBob Glamm
04/23/2019, 5:17 PMfx
for non-IO
types. Thanks @AdrianRaFoAdrianRaFo
04/23/2019, 5:21 PMdr.dreigh
04/23/2019, 5:52 PMx = Just 1
y = Just 2
(+) <$> x <*> y
which would yield an Otional<int> of 3?
You can then fmap (> 3) over that to give you your optional<Boolean> ?
Apologies, I have only just started looking at Arrow, I can see applicative in the docs for optional, I just can’t find a way to lift a function over the applicatives.
Would be keen to know if this is possible in Arrowdr.dreigh
04/23/2019, 6:02 PMsimon.vergauwen
04/23/2019, 6:04 PMap
in Arrow. It’s not so popular pattern in Kotlin because of language semantics, similar situation in Scala.dr.dreigh
04/23/2019, 6:04 PMOption.applicative().run { Some(1).ap(Some(2)).ap(Some({ x: Int, y: Int -> x + y })) }
simon.vergauwen
04/23/2019, 6:04 PMsimon.vergauwen
04/23/2019, 6:05 PMdr.dreigh
04/23/2019, 6:06 PMsimon.vergauwen
04/23/2019, 6:07 PM(+) <$> x
returns Maybe (Int -> Int)
dr.dreigh
04/23/2019, 6:09 PMsimon.vergauwen
04/23/2019, 6:11 PMap
is useful when doing FP stuff but I’ve found that it becomes less useful in vanilla Kotlin. Most of the times there is a similar snippets that reach much better.dr.dreigh
04/23/2019, 6:13 PMsimon.vergauwen
04/23/2019, 6:14 PM