raquo/Airstream

Side effects in functions passed to operators

cubuspl42 opened this issue · 1 comments

Does Airstream support functions passed to transforming operators (for example, but not limited to,EventStream.map and Signal.map) to have side effects?

raquo commented

Neither Airstream nor Scala have a concept of "side effects", so we can't really disallow that*. So yes, you can do dirty things inside operator callbacks, such as reading or updating a Var. It's not encouraged, but sometimes this can actually be useful to avoid more complex observable composition.

Relatedly, Airstream has shared execution, e.g. the fn in stream.map(fn) will be executed at most once per incoming event, whereas other streaming libraries tend to execute it N times per event if the resulting stream has N observers.

*BUT: you're not allowed to throw when providing some callbacks. These are marked with Must not throw in scaladoc comments. Usually there isn't a technical reason for it, I just felt it was unnecessary at the time. Maybe I'll get to adding guards in such cases some time.

PS I'm moving these issues to discussions. Apparently this closes the original issue, but the point is to move, not to close the discussion.