hi, I see `Option` is deprecated in 0.11. What's t...
# arrow
m
hi, I see
Option
is deprecated in 0.11. What's the migration path for functions that I was calling on
Option
(specifically
traverse
and
foldMapM
) - is there an import that will make them available on nullable types or anything like that?
s
To replace
Option#traverse
we can project new syntax in
Functor
.
Copy code
fun <F, A : Any, B> Kind<F, A?>.mapNullable(FA: Functor<F>, f: (A) -> B): Kind<F, B?> =
  FA.run { 
    map { it?.let(f) }
  }
and
foldMapM
could be replaced by syntax on
Monad
but I'm not sure what we could name it best there 😅 It'd be like
flatMapNullable
but it takes a
Monoid
instead of returning
?
like the
mapNullable
version of
traverse
.
Copy code
fun <F, A : Any, B, MA, MO> Kind<F, A?>.foldMapM(ma: MA, mo: MO, f: (A) -> Kind<F, B>): Kind<F, B>
  where MA : Monad<F>, MO : Monoid<B> = ma.run {
  mo.run {
    flatMap { a ->
      a?.let(f)?.map { b ->
        b.combine(mo.empty())
      } ?: just(mo.empty())
    }
  }
}
Both don't currently exist yet, but I think would be welcomed contributions.
m
hmm, tbh most of the value of using those functions on option is in the uniformity
custom monad/traversable types are still supported, right? I think I'd sooner define my own option type then.
s
Totally valid!
Option
is being moved to a separate module btw, so you can still keep using it if you want to for uniformity! We're moving it our of Arrow-Core since we felt it didn't feel like a "core" data type given
?
in the language. Reference: https://github.com/arrow-kt/arrow-core/pull/239
m
ah cool. I'll stick with it then. Where's the module it's going to? (Also, is there a similar thing for
IO
in that case?)
s
That module will probably stat within the arrow-core repository. There is no such thing for
IO
, mostly since the maintenance and/or further of
IO
cannot be justified there where as it can for
Option
.
☝️ 1