ImmutableList

example_immutable_list.py
from pymonet.immutable_list import ImmutableList
from pymonet.utils import increase

lst = ImmutableList.of(1, 2, 3)

lst.map(increase) # ImmutableList.of(2, 3, 4)
lst.filter(lambda item: item % 2 == 0) # ImmutableList.of(2)
lst.find(lambda item: item % 2 == 0) # 2
lst.map(increase) # ImmutableList.of(2, 3, 4)
class pymonet.immutable_list.ImmutableList(head: T = None, tail: Optional[pymonet.immutable_list.ImmutableList[~ T][T]] = None, is_empty: bool = False)

Immutable list is data structure that doesn’t allow to mutate instances

__add__(other: pymonet.immutable_list.ImmutableList[~ T][T]) → pymonet.immutable_list.ImmutableList[~T][T]

If Maybe is empty return new empty Maybe, in other case takes mapper function and returns result of mapper.

Parameters

mapper (Function(A) -> Maybe[B]) – function to call with Maybe.value

Returns

Maybe[B | None]

append(new_element: T) → pymonet.immutable_list.ImmutableList[~T][T]

Returns new ImmutableList with elements from previous one and argument value on the end of list

Parameters

new_element – element to append on the end of list

Returns

ImmutableList[A]

filter(fn: Callable[[Optional[T]], bool]) → pymonet.immutable_list.ImmutableList[~T][T]

Returns new ImmutableList with only this elements that passed info argument returns True

Parameters

fn (Function(A) -> bool) – function to call with ImmutableList value

Returns

ImmutableList[A]

find(fn: Callable[[Optional[T]], bool]) → Optional[T]

Returns first element of ImmutableList that passed info argument returns True

Parameters

fn (Function(A) -> bool) – function to call with ImmutableList value

Returns

A

map(fn: Callable[[Optional[T]], U]) → pymonet.immutable_list.ImmutableList[~U][U]

Returns new ImmutableList with each element mapped into result of argument called with each element of ImmutableList

Parameters

fn (Function(A) -> B) – function to call with ImmutableList value

Returns

ImmutableList[B]

reduce(fn: Callable[[U, T], U], acc: U) → U

Method executes a reducer function on each element of the array, resulting in a single output value.

Parameters

fn (Function(A, B) -> A) – function to call with ImmutableList value

Returns

A

unshift(new_element: T) → pymonet.immutable_list.ImmutableList[~T][T]

Returns new ImmutableList with argument value on the begin of list and other list elements after it

Parameters

new_element – element to append on the begin of list

Returns

ImmutableList[A]