Pysistence v0.4.0 documentation

PLists - immutable lists


A PList is a list that never changes, even when you add to it. To instantiate it, you should use the make_list convenience function:

>>> from pysistence import make_list
>>> make_list(1,2)
PList([1, 2])

As with any other list, items may be added to it:

>>> from pysistence import make_list
>>> l = make_list(1,2)
>>> l.cons(0)
PList([0, 1, 2])

The same is true of removing items:

>>> from pysistence import make_list
>>> l = make_list(1,2,3)
PList([2, 3])

You can remove any number of arbitrary arguments:

>>> from pysistence import make_list
>>> ls = make_list(1, 2, 3)
>>> ls.without(2)
PList([1, 3])

You can even chain these things together:

>>> from pysistence import make_list
>>> ls = make_list(1, 2, 3)
PList([4, 3])



Make a new persistent list from items.

class pysistence.persistent_list.PList(first, rest=None)

A PList is a list that is mutated by copying. This makes them effectively immutable like tuples. The difference is that tuples require you to copy the entire structure. PLists will reuse as much of your existing list as possible.


Concatenate this list with another list.


Get the first item in this list.


The first item of the rest. Equivalent to

replace(old, new)

Return a new list that has new instead of old. Will raise an exception if old is not found.


Get all items except the first in this list.


Make a new PList that is the reverse of this one.


Return a new PList with items removed