If I call a function and use the .? operator, will...
# announcements
t
If I call a function and use the .? operator, will the function not be called when the .? fails?
k
which function do you mean?
update
or
copy
?
if
childCatalogue
is null,
childCatalogue?.copy
will not be called and will simply return null, but
update
will still be called
t
Thought so as well, thanks
👍 1
What would be a cleaner way to only execute some code with an iterable if it is in the Iterable list
the any { } predicate doesn't seem to run itself only when there is an object in the itterable collection
I guess a forEach{} would do the same but is there something that would only work on the first element
k
what do you mean by "if it is in the Iterable list"?
t
I have this query that returns an iterable and I know that if it returns then it will either have no elements or just one element
k
you can do
iterable.singleOrNull()?.let { /* put your code here */ }
t
but forEach implies that there are more than one elements which doesn't rub me the right way, although it would work as expected
I always forget that let{} predicate, thanks a lot 😄
k
you can always do the imperative way and write
if (iterable.count() == 1) doStuff()
t
Yeah, I know, but that adds some clutter
k
true, in some situations
let
can be a bit more elegant
👍 1