Documentation

lazylist

Haskell-like lazily evaluated list in Python.

class lazylist.LazyList(func, getsize=None, inf=False)

Lazily evaluated list.

func

Function that accepts int as index and returns the corresponding value. Should raise IndexError when out of bound.

getsize

Function with no arguemnt and returns the supposed size. It is optional but should be provided when the size can be determined without evaluating all elements.

inf

Bool that indicates if the list is an infinite one. When inf is True, there’s no need to provide getsize.

append(a)

Returns list with the provided element appended to the end.

call(f)

Returns list which is the result of applying f to self.

elem_index(item)

Returns the index of corresponding element. Returns -1 if not found.

reverse()

Returns reveresed list.

to_list()

Returns corresponding Python built-in list. Raises ValueError if called on infinite list.

lazylist.check_finite(func)

Raises ValueError if the annonated function is called on infinite instance

lazylist.cycle(xs)

Returns an infinite list which is an infinite repetition of xs.

lazylist.empty = <lazylist.LazyList object>

Empty list.

lazylist.iterate(f, x)

Returns an infinite list of repeated applications of f to x.

lazylist.make_lazylist(iterable)

Returns a list whose values are adapted from supplied iterable.

lazylist.naturals = <lazylist.LazyList object>

List of natural numbers.

lazylist.ones = <lazylist.LazyList object>

List of ones.

lazylist.repeat(item)

Returns an infinite list where every element is x.

lazylist.zeros = <lazylist.LazyList object>

List of zeros.