You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When doing multiple ensure checks for the same variable, if an error condition arises, it is not raised and collected.
See code below
sealed class interface BookProblem {
data object BookTypeIsRequired: BookProblem
data object BookTypeCannotBeLarge: BookProblem
}
enum class BookType {
None,
Large,
Small
}
data class Book(val type: BookType, ) {
companion object {
fun create(type: BookType) = either {
zipOrAccumulate(
{ ensure(type != BookType.None) { BookProblem.BookTypeIsRequired } },
{ ensure(type != BookType.Large) { BookProblem.BookTypeCannotBeLarge } },
) { _, _ ->
Book(type)
}
}
}
}
Doing two ensure checks on the type variable does not return a NonEmptyList(BookProblem) if one of the conditions fails i.e. if type == BookType.None the error will not be raised and the code will assume the variable is valid and proceed to create the Book object.
The following code fixes the issue but forces me to use only one BookProblem to describe two different types of errors:
Arrow versions/libs:
When doing multiple ensure checks for the same variable, if an error condition arises, it is not raised and collected.
See code below
Doing two ensure checks on the
type
variable does not return aNonEmptyList(BookProblem)
if one of the conditions fails i.e. iftype == BookType.None
the error will not be raised and the code will assume the variable is valid and proceed to create the Book object.The following code fixes the issue but forces me to use only one
BookProblem
to describe two different types of errors:The text was updated successfully, but these errors were encountered: