jkoudys / immutable.php

Immutable collections, with filter, map, join, sort, slice, and other methods. Well-suited for functional programming and memory-intensive applications. Runs especially fast in PHP7.
MIT License
346 stars 20 forks source link

Build SliceIterator for more efficient slices #3

Closed jkoudys closed 9 years ago

jkoudys commented 9 years ago

To be javascript-like, the original implementation made a slice as a full clone. However, this is only necessary in JS specifically because an array is mutable. On an immutable array, it makes more sense to define an ArrayAccess, JsonSerializable LimitIterator to simply access a subset of the target ImmArray. It's not going anywhere in memory, so no need to clone when we can simply iterate at an offset.