PyoSequence
Bases: PyoCollection[T], PyoReversible[T], Sequence[T], ABC
flowchart TD
pyochain.abc._sequences.PyoSequence[PyoSequence]
pyochain.abc._collection.PyoCollection[PyoCollection]
pyochain.abc._iterable.PyoIterable[PyoIterable]
pyochain.rs.Pipeable[Pipeable]
pyochain.rs.Into[Into]
pyochain.rs.Inspect[Inspect]
pyochain.rs.Checkable[Checkable]
pyochain.abc._collection.PyoContainer[PyoContainer]
pyochain.abc._collection.PyoSized[PyoSized]
pyochain.abc._sequences.PyoReversible[PyoReversible]
pyochain.abc._collection.PyoCollection --> pyochain.abc._sequences.PyoSequence
pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
pyochain.rs.Pipeable --> pyochain.abc._iterable.PyoIterable
pyochain.rs.Into --> pyochain.rs.Pipeable
pyochain.rs.Inspect --> pyochain.rs.Pipeable
pyochain.rs.Checkable --> pyochain.abc._iterable.PyoIterable
pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
pyochain.abc._sequences.PyoReversible --> pyochain.abc._sequences.PyoSequence
click pyochain.abc._sequences.PyoSequence href "" "pyochain.abc._sequences.PyoSequence"
click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
click pyochain.rs.Pipeable href "" "pyochain.rs.Pipeable"
click pyochain.rs.Into href "" "pyochain.rs.Into"
click pyochain.rs.Inspect href "" "pyochain.rs.Inspect"
click pyochain.rs.Checkable href "" "pyochain.rs.Checkable"
click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
click pyochain.abc._sequences.PyoReversible href "" "pyochain.abc._sequences.PyoReversible"
Extends PyoCollection[T] and collections.abc.Sequence[T].
Is the shared ABC for concrete sequences: Seq, Range and Vec.
Any concrete subclass must implement the required Sequence dunder methods:
__getitem____len____contains____iter__
Example
>>> from pyochain.abc import PyoSequence
>>> class MySeq(PyoSequence[int]):
... def __init__(self, data: list[int]):
... self._data = data
...
... def __getitem__(self, index: int) -> int:
... return self._data[index]
...
... def __len__(self) -> int:
... return len(self._data)
...
... def __contains__(self, item: int) -> bool:
... return item in self._data
...
... def __iter__(self) -> Iterator[int]:
... return iter(self._data)
>>>
>>> my_seq = MySeq([10, 20, 30])
>>> my_seq.first()
10
>>> my_seq.rev().collect()
Seq(30, 20, 10)
Source code in src/pyochain/abc/_sequences.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
get(index)
get(index: int) -> Option[T]
get(index: slice) -> Option[Sequence[T]]
Return the element at the specified index as Some(value), or None if the index is out of bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | slice
|
The index or slice of the element to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Option[T] | Option[Sequence[T]]
|
Option[T] | Option[Sequence[T]]: |
Example
>>> from pyochain import Seq
>>> data = Seq((10, 20, 30))
>>> data.get(1)
Some(20)
>>> data.get(5)
NONE
Source code in src/pyochain/abc/_sequences.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |