3 ms·
It's not lazy, it returns iterator. There is a difference, you can't slice or index its result anymore. Compare to Clojure or Haskell map, which are truly lazy.
by Suor 12y ago
It's not lazy, it returns iterator. There is a difference, you can't slice or index its result anymore. Compare to Clojure or Haskell map, which are truly lazy.
- e12e 12y agoTo be fair, the syntax might not be as clean, but isn't: m = map(lambda x: x*2, range(100000000000000000000)) i = itertools.islice(m, 10**6, None) next(i) Somewhat equivalent? This does seem a little slow calculating the first million squares, but subsequent calls to next(i) are snappy(ish). I'm not sure how close you could get to "truly" lazy sequences combining count, zip and slice, though.
- judk 12y agoIs it true that this is O(1) in Haskell? (Making up function names but you get the idea) (fmap a function anArray) `get` n ? How does fmap construct its value?
- codygman 12y agoHow fmap constructs it's value depends on how that type implements the functor typeclass I believe.
- scottdw2 12y agoThis is a nitpick, but it is lazy. It's not represented in head normal form, but it's still lazy. The limitations you mentioned are not an artifact of the implementation being eager(because it's not eager), but instead are an artifact of the representation used.