Is there any built-in way to ensure lists are empty, which gives a nel when it fails? Sort-of like
Copy code
ensureEmpty(list) { nel -> ProblemWithNel(nel) }
s
simon.vergauwen
03/07/2024, 8:52 AM
No, but I've had more of these questions and I think we should consider facilitating them.
Adding useful functions to the DSL can benefit multiple types, and DSLs at once.
simon.vergauwen
03/07/2024, 8:53 AM
Some transformations, especially
NonEmpty
are hard since after the
isNotEmpty
or
isEmpty
check you don't know anything.
e
Emil Kantis
03/07/2024, 8:56 AM
Want me to raise an issue? Or will you create one? π I guess you know more about what the desired API should look like. Personally I added this:
Copy code
@RaiseDSL
public inline fun <Error, B : Any> Raise<Error>.ensureEmpty(
value: Collection<B>,
raise: (NonEmptyList<B>) -> Error,
) {
value.toNonEmptyListOrNull()?.let { nel ->
raise(raise(nel))
}
}
s
simon.vergauwen
03/07/2024, 9:03 AM
That's perfect for a impl/solution βΊοΈ Yes, please create a ticket. Not sure if we'll add this one but I think it's good to have an open discussion. I know @timrijckaert once proposed the opposite.
ensureNotEmpty
for
Iterable
->
NonEmptyList
.
π«Ά 1
simon.vergauwen
03/07/2024, 9:04 AM
There were a couple more, but I cannot remember them.