nozavroni / collections

🐧 Just another collections library for PHP5.6+
Other
1 stars 0 forks source link

Immutable collections #52

Open nozavroni opened 7 years ago

nozavroni commented 7 years ago

Collections should be immutable. Refactor every method in collection class to return a new collection. Never change state of a collection. Ever.

Tons of interesting stuff here: http://clojure-doc.org/articles/language/collections_and_sequences.html

My main take-away... CollectionInterface should only contain a very small, core set of methods that will be available on ALL collection types (I suppose I already knew I was going to need to do this, but this reinforces it). Then take all the methods you peeled from CollectionInterface and use them to create SequenceInterface (numerically indexed, always in order), MapInterface (essentially what collection is now), SetInterface (unique set of values of a particular type), NumericInterface (all values are numeric), ListInterface (linked list), ArrayInterface (ArrayAccess), FixedCollectionInterface (size cannot change), StructInterface (I'm not too clear on this one) etc.

nozavroni commented 7 years ago

Need to research how linked lists are used in functional languages to help with performance when creating a new collection for every operation. Also use spl data structures if possible to do it yourself.