Is there a way to Memorize or Materialize an IEnumerable?

前端 未结 3 1691
孤街浪徒
孤街浪徒 2020-12-06 02:30

When given an d you could be dealing with a fixed sequence like a list or array, an AST that will enumerate some external datasource, or even an AST on some exi

3条回答
  •  一向
    一向 (楼主)
    2020-12-06 02:51

    Check out this blog post I wrote a couple of years ago: http://www.fallingcanbedeadly.com/posts/crazy-extention-methods-tolazylist

    In it, I define a method called ToLazyList that effectively does what you're looking for.

    As written, it will eventually make a full copy of the input sequence, although you could tweak it so that instances of IList don't get wrapped in a LazyList, which would prevent this from happening (this action, however, would carry with it the assumption that any IList you get is already effectively memoized).

提交回复
热议问题