Search code examples
kotlinarrow-kt

In Arrow Kotlin, what's the replacement for deprecated sequence?


In the following Arrow Kotlin 1.2.0 code:

val map: List<Either<NonEmptyList<HeroIdError>, HeroId>> = TODO()
val postSequence: Either<NonEmptyList<HeroIdError>, List<HeroId>> = map.sequence()

I put the TODO() for clarity.

In the above, the '.sequence()' method is deprecated. The @Deprecated annotation states:

Traverse for Either is being deprecated in favor of Either DSL + NonEmptyList.map.

Replace with: let<NonEmptyList<A>, Either<E, NonEmptyList<B>>> { nel -> either<E, NonEmptyList<B>> { nel.map<B> { f(it).bind<B>() } } }

Imports: arrow.core.raise.either

i don't manage to get anything related to the above to work: mind sharing an example please?

I tried various combination if map/bind without success (as well as search engine or Bing conversation ChatGPT4 powered).

thanks a lot


Solution

  • I finally got it working, changing

    .sequence()
    

    to

    .let { l -> either { l.bindAll() } }
    

    now reading the doc to understand the change ^^