3 ms·
> Well, iterators are cool and useful, but many operators like map(), filter() and flatMap() can be applied on things that don't necessarily produce values. Yo
by Veedrac 11y ago
> Well, iterators are cool and useful, but many operators like map(), filter() and flatMap() can be applied on things that don't necessarily produce values.
You've lost me. You need to apply the function in `flatMap` to something, and `flatMap` by definition will output zero or more values.
So what do you mean?
- bad_user 11y agoThe signature of flatMap is something like this: flatMap[M,A,B](cc: M[A], f: A => M[B]): M[B] So given that you respect its signature, M[A] is not necessarily a producer of values. It can be anything and it helps if you think about it not like a collection or a container, but more like a context. For example M[A] could be a function of type S => (A, S). And then you could map and flatMap on such functions to produce other functions. This is the "state monad" btw.