<@U68N4SR27> Don't call `.stream()` it gives you a...
# announcements
@ianandrewclark Don't call
it gives you a java stream not a kotlin list, you should be able to call
.forEach { println(it) }
directly on the collection.
Am I missing context? Why would you suggest mapping the stream contents with
? Might he not need the list for something else?
Also it might be more concise to just
My apologies, I made an assumption he was try to convert something to a list in order to perform some sort of list functions on it. map/filter/foreach. Furthermore if he can call stream on the object then isn't it most likely already a collection?
Any yes that is more concise 😉
Sorry, I’m getting the Stream from a BufferedReader.lines() method
Is there a convenient way I can get a Sequence instead?
hmm, there’s supposed to be an extension function,
, provided by Kotlin, but I’m not sure that’ll be terribly helpful if you can’t use any of the extension methods
👍 1
Hmm, let me check that out…
Nice, that worked, thank you @Shawn;)
👍 1
np @Ian. Might be worth mentioning that the source for that method includes this comment:
Copy code
We suggest you try the method [useLines] instead which closes the stream when the processing is complete.
I’m not sure if this is directly relevant to you, but it may be worth investigating
takes in a lambda, specifically
(Sequence<String>) -> T
, and handles cleanup for you
Yes, in this case I actually needed a
, so toList() worked out fine 🙂
👍 1