I found this foreach(_ => ()) in a code that uses Monix stream, I am not understanding the meaning. Can someone explain me this?
monix_concurrent_subject.foreach(_ => ())
As urmaul explained in the comments, it depends:
If the datastructure is eager, it does nothing. Examples are List, Option etc.
If the datastructure is lazy, it initialises its content. An example is a Stream.
Also as foreach returns nothing, it implies that somewhere will be a Side-Effect in the code before the foreach.
If you check the API (ConcurrentSubject.html#foreach) it states:
foreachL(cb: (O) ⇒ Unit): Task[Unit]Creates a new Task that will consume the source observable, executing the given callback for each element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With