Preventing Undesired Side-Effects in Enumerators
• CommentsI normally don’t write a post just to link to a post on another blog, because I want this blog to be mostly original content. However, today I read an excellent article/blog post on the B# blog: Taming Your Sequence’s Side-Effects Through IEnumerable.Let.
The author does a great job describing how side effects in sequences can be problematic, and how to create a “MemoizeEnumerable” to prevent multiple evaluations of a source sequence. It’s a great application of dynamic programming (see The Algorithm Design Manual).
Side effects when dealing with enumerables are rare; few people have needed an “IEnumerable.Let” operator. Side effects are much more common when dealing with events, e.g., the up-and-coming Rx framework. I highly recommend reading the B# blog entry to understand the rationale behind “Let” for enumerables; it will prove good background information to understand “Let” for observables.