Remove unnecessary lambda pointer from first(predicate) error message. #4220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
first
is called on a flow that doesn't satisfy the predicate it throws aNoSuchElementException
with the message"Expected at least one element matching the predicate $predicate"
. The use of$predicate
implies printing out the lambda however, the lambda's pointer is printed instead.As far as I know, getting the lambda's string representation is not feasible. Therefore I feel it is best to remove
$predicate
from the error message to make it more readable and remove unnecessary information.For example, running
flowOf(1, 2, 3).first {it > 4}
https://pl.kotl.in/jjalTWjTtreturns the error message
Where the predicate
flowOf(1, 2, 3).first {it > 4}
evaluates tooFunction2<java.lang.Integer, kotlin.coroutines.Continuation<? super java.lang.Boolean>, java.lang.Object>
I feel that there is no added value from the lambda pointer being printed. It seems better for the developer to use the line number and read the lambda from source code.