GenericList
Unfortunately the List
is a reserved keyword in PHP so the list in Munus is simply called GenericList
.
An immutable GenericList
is an eager sequence of elements.
Its immutability makes it suitable for concurrent programming (which not directly supported in PHP ;)).
GenericList
is composed of a head and a tail. Head contains first value, tail is another list instance.
The list has two implementations available:
Nil
which stand for empty listCons
which stand for a list with one or more elements (consisting of a head and tail)
#
ConstructionYou can also create GenericList
for a range of numbers:
#
MethodsList contains couple specific methods (in addition to those normally available for any Traverasable
):
prepend($element): self
- add $element to the begging of list and returns new instanceappend($element): self
- add $element to the end of list and returns new instancereverse(): self
- change the order of elements to reverse and returns new instance