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
Sometimes, inside Raise<Nel<E>>, a failed precondition stops the computation from going further, and short-circuiting is necessary.
Let's image a recursive tree. A node is valid if it satisfies the predicate a(), and all its children satisfy it as well. I'm writing this example with context receivers for readability, but it is already the case now.
When there are multiple short-circuiting operations, writing ensure() { nonEmptyListOf() } is inconvenient and makes the code more complicated. Instead, the library could provide a variant of ensure and ensureNotNull that encapsulates this behavior:
@CLOVIS-AI what if we use the extension function instead? i.e.T.nel(): NonEmptyList<T> would that improve readability?
something like
ensure(...) {
Failure.A().nel()
}
Just my opinion, I think I would prefer to make Raise<E> contextual operations ensure / bind / raise just operate on the E type.. If we add another bind for the inner E in Raise<Nel<E>>, I'm afraid that would make it very confusing for early adopters…
What version are you currently using?
1.2.0-RC
What would you like to see?
Sometimes, inside
Raise<Nel<E>>
, a failed precondition stops the computation from going further, and short-circuiting is necessary.Let's image a recursive tree. A node is valid if it satisfies the predicate
a()
, and all its children satisfy it as well. I'm writing this example with context receivers for readability, but it is already the case now.When there are multiple short-circuiting operations, writing
ensure() { nonEmptyListOf() }
is inconvenient and makes the code more complicated. Instead, the library could provide a variant ofensure
andensureNotNull
that encapsulates this behavior:As a bonus, what about a
RaiseNel
type alias?The text was updated successfully, but these errors were encountered: