arrow-core-data / arrow.core / kotlin.collections.Iterable / ifThen

ifThen

inline fun <A, B> Iterable<A>.ifThen(fb: Iterable<B>, ffa: (A) -> Iterable<B>): Iterable<B>

Logical conditional. The equivalent of Prolog’s soft-cut. If its first argument succeeds at all, then the results will be fed into the success branch. Otherwise, the failure branch is taken.

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
   listOf(1,2,3).ifThen(listOf("empty")) { i ->
     listOf("$i, ${i + 1}")
   }
  //sampleEnd
  println(result)
}

Do you like Arrow?

Arrow Org
<