Skip to content

Instantly share code, notes, and snippets.

@garthgilmour
Created December 17, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garthgilmour/1fb98cb7f41cc4164705cdbc5f1ff8a7 to your computer and use it in GitHub Desktop.
Save garthgilmour/1fb98cb7f41cc4164705cdbc5f1ff8a7 to your computer and use it in GitHub Desktop.
fun demoTraverse(input: List<String>) {
val failure = { error: String -> println(error) }
val success = { results: List<String> ->
println("Results are:")
results.map { s -> "\t$s" }
.forEach(::println)
}
val result = input.traverse(Either.applicative(), ::propertyViaJVM)
result.fix()
.fold(failure) { success(it.fix()) }
}
@clojj
Copy link

clojj commented Jan 23, 2021

in Arrow 0.12 this looks like this

    val result: Either<String, List<String>> = input.traverseEither(::propertyViaJVM)
    result.fold(failure) { success(it) }

even more nice for the enterprise bees ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment