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

commonMain.target.core.Functions.kt Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package target.core

import arrow.core.*

/**
 * Validates this list and returns either a list of all failures, or a validated list.
 */
fun  List>.validate(): Either, List> {
    val failureList = mutableListOf()
    val successList = mutableListOf()
    forEach {
        it.fold(failureList::add, successList::add)
    }

    return failureList.toNonEmptyListOrNull()?.left() ?: successList.right()
}

/**
 * Validates this list and returns either a list of all failures, or a validated list.
 */
fun  Nel>.validate(): Either, Nel> {
    val failureList = mutableListOf()
    val successList = mutableListOf()
    forEach {
        it.fold(failureList::add, successList::add)
    }

    return failureList.toNonEmptyListOrNull()?.left() ?: successList.toNonEmptyListOrNull()!!.right()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy