bind

fun <T> Raise<NonEmptySet<ConstraintViolation>>.bind(validationResult: ValidationResult<T>): T

Binds the ValidationResult to the Raise computation.

You can bind the result of the validation to a Raise computation:

val validateBookName = Validator<String> { isNotBlank() }
val validateAuthorName = Validator<String> { isNotBlank() }

fun combineBookAndAuthor(bookName: String, authorName: String) = either {
val book = bind(validateBookName(bookName))
val author = bind(validateAuthorName(authorName))
"${book.trim()} by ${author.trim()}"
}

Non-blank strings returns Either.Right because the validation was successful and the either block could complete:

combineBookAndAuthor("  The Lord of the Rings  ", "  J. R. R. Tolkien  ")
// Returns: Either.Right(value = "The Lord of the Rings by J. R. R. Tolkien")

Whereas, a single blank string fails the validation and interrupts the either block, returning a Either.Left of constraint violations:

normalizeBookName("  ", "  J. R. R. Tolkien  ") // Returns: Either.Left<NonEmptySet<ConstraintViolation>>

Return

The validated value on successful result.