Arrow 1.1.3 is now available

Arrow 1.1.3 is now available

We are happy to announce Arrow 1.1.3, with fixed Resource release order, variance changes for the Effect DSL, and several community contributions.

Thanks for all the feedback and contributions!

Table of Contents

Features and Fixes

  • One important update to the Resource API is fixing the release order, which was incorrect in prior 1.1.X releases.

  • Kotlin idiomatic NonEmptyList construction: listOf(1, 2, 3).toNonEmptyListOrNull()

  • There are variance improvements on Effect<R, A>, EffectScope<R>, as well as for EagerEffect<R, A> and EagerEffectScope<R>, allowing bind and shift to take advantage of the type hierarchy of R and A.

sealed interface DomainError
data class SomeDomainError(val error: String, val throwable: Throwable?) : DomainError
object UnknownError : DomainError

sealed interface Response
data class StringResponse(val value: String) : Response
data class IntResponse(val value: Int) : Response

private fun serverRestarts(): Effect<DomainError, IntResponse> = TODO()
private fun fetchServerLocation(): Effect<SomeDomainError, StringResponse> = TODO()

fun serverLocation(): Effect<DomainError, Response> =
  effect {
    val restarts = serverRestarts().bind()

    if (restarts > 4) {
      shift(UnknownError)
    } else {
      fetchServerLocation().bind()
    }
  }

Existing applications using Either, Validated, or Option can refactor out those Types and focus on the result type, as in the following example:

import arrow.core.continuations.either

data class Person(val id: Int, val name: String)

private suspend fun getPersonById(id: Int): Option<Person> = TODO()

suspend fun fetchPerson(id: Int): Either<DomainError, Person> =
  either {
    val person: Person =
      getPersonbyId(id)
        .bind { SomeDomainError("Cant fetch person", null) }
    ensure(person.id == id) { SomeDomainError("Fetched Person has ${person.id}, but a Person with $id was requested") }
    person
  }

With EffectScope and context receivers, this can be refactored to:

context(EffectScope<DomainError>)
private suspend fun getPersonById(id: Int): Person? = TODO()

context(EffectScope<DomainError>)
suspend fun fetchPerson(id: Int): Person {
  val person: Person =
    ensureNotNull(getPersonbyId(id)) { SomeDomainError("Cant fetch person", null) }

  ensure(person.id == id) { SomeDomainError("Fetched Person has ${person.id}, but a Person with $id was requested") }
  return person
}

Check out another example here.

Deprecations

  • flatMap and map in EagerEffect have been deprecated and will be removed in the next major release in favor of bind()
  • NonEmptyList.fromList and NonEmptyList.fromListUnsafe have been deprecated and will be removed in the next major release in favor of toNonEmptyListOrNull
  • arrow-core-test, arrow-fx-coroutines-test, and arrow-optics-test are being deprecated and will be removed in 1.2. We recommend using the libraries in kotest-extension-arrow instead.

More community contributions

  • Add Resource.allocated() to decompose Resource into its allocate and… (#2820) by Jeff Martin
  • Refactor - #2812 iterable separate performance (#2815) by Giorgos Makris
  • add separateEither and separateValidated test (#2814) by Petrus Nguyễn Thái Học
  • Two small deprecations by Simon Vergauwen
  • Update docs from version 1.0.1 to 1.1.2 (#2808) by Tobias Hermann
  • Stop relying on getOrNull as generic failure signal (#2804) by Simon Vergauwen
  • Update API compatibility validator version (#2794) by Alejandro Serrano
  • Enable builder inference for optics copy (#2792) by Alejandro Serrano
  • Backport flattening token/shift into Cont (#2791) by Simon Vergauwen
  • Fix example in documentation (#2790) by Oliver Becker
  • Fix usage of startCoroutineUninterceptedOrReturn replaces #2783 (#2789) by Simon Vergauwen
  • Generalized copy for optics (#2777) by Alejandro Serrano
  • Support generics and inner classes in @optics (#2776) by Alejandro Serrano
  • deprecate orNull Either extension function (#2773) by Imran Malic Settuba
  • Fix #2779 (#2783) by Simon Vergauwen
  • fix ruby set up (#2775) by Imran Malic Settuba
  • add ruby setup (#2774) by Imran Malic Settuba
  • Consent management osano (#2755) by Israel Pérez
  • update gradle wrapper (#2771) by Imran Malic Settuba
  • Refine the Arrow version selector (#2770) by Francisco Diaz
  • catch for EffectScope (#2746) by Alejandro Serrano
  • [2761] Add explicit visibility modifier for all the generated optics (#2763) by Yevhen Kazmin
  • Fix #2764 & #2760 (#2765) by Simon Vergauwen
  • Resource deprecate traverseResource, fixes arity-4 (#2750) by Simon Vergauwen
  • Update all dependencies except the compiler version (#2757) by Alejandro Serrano
  • Update kotlin-js-store/yarn.lock (#2756) by Alejandro Serrano
  • Deprecate arrow test modules (#2753) by Imran Malic Settuba
  • max and min methods for NonEmptyList (#2622) by Dorian Sarnowski
  • Small docs fix for widen function (#2754) by Thanh Le
  • add merge function for *Effect (#2752) by Imran Malic Settuba
  • Fix build, inject kotlin.mpp.enableCompatibilityMetadataVariant in CI (#2751) by Simon Vergauwen
  • fix alpha tag build task (#2749) by Imran Malic Settuba
  • Add kotlin.mpp.enableCompatibilityMetadataVariant=true (#2747) by Javier Segovia Córdoba
  • Bump versions (#2745) by Simon Vergauwen
  • Fix compilation warnings by replacing usages of deprecated methods (#2742) by Daniel Wojda
  • add merge to validated (#2739) by Agustín Ottolini
  • Convert Arrow core effect into a non-inline function (#2734) by Francisco Diaz
  • Fix some compilation and test warnings (#2741) by Daniel Wojda
  • Rename duplicated test name (#2740) by Daniel Wojda
  • revert arrow-gradle-config (#2738) by Imran Malic Settuba
  • improve generate-tag workflow (#2731) by Imran Malic Settuba
  • Improve Nel constructor (#2728) by Simon Vergauwen
  • Add command to install bundler (#2729) by Francisco Diaz
  • revert java setup (#2730) by Imran Malic Settuba
  • Update all dependencies (#2709) by renovate[bot]
  • add Continuations and programs to overview section in arrow core (#2723) by Imran Malic Settuba
  • deprecate flatMap and map in EagerEffect (#2726) by Imran Malic Settuba
  • feat: contravariance for R, A in Effect, EagerEffect and in for *EffectScope (#2722) by Imran Malic Settuba
  • rename traverseX and sequenceX functions in core (#2715) by Imran Malic Settuba
  • Add kotlin-js-store folder (#2724) by Francisco Diaz
  • Fix traversal code samples of docs (#2719) by Benedikt Schwab
  • invert resource release order (#2714) by Phil Davies
  • Fix publish sync (#2717) by Javier Segovia Córdoba
  • Add new workflow for publishing the landing page (#2716) by Francisco Diaz
  • Update libs.versions.toml (#2712) by Imran Malic Settuba

These are some templates to try out the new release:

If you run into any issues while upgrading, check the KotlinLang #arrow channel.

Ensure the success of your project

47 Degrees can work with you to help manage the risks of technology evolution, develop a team of top-tier engaged developers, improve productivity, lower maintenance cost, increase hardware utilization, and improve product quality; all while using the best technologies.