All Downloads are FREE. Search and download functionalities are using the official Maven repository.

app.cash.quiver.extensions.List.kt Maven / Gradle / Ivy

Go to download

Quiver library providing extension methods and type aliases to improve Arrow

The newest version!
package app.cash.quiver.extensions

import arrow.core.Either
import arrow.core.Option
import arrow.core.filterOption
import arrow.core.raise.either

/**
 * Returns a list without Nones
 */
fun  List>.filterNotNone(): List = filterOption()

/**
 * Constructs a flattened list without Nones
 */
fun  listOfSome(vararg elements: Option): List = elements.toList().filterNotNone()

/**
 * Returns a list containing only the non-None results of applying the given transform function
 * to each element in the original collection.
 */
inline fun  List.mapNotNone(f: (A) -> Option): List =
  this.flatMap { f(it).fold(::emptyList, ::listOf) }