Seq
Bases: PyoSequence[T], ArgsWrapper[T]
flowchart TD
pyochain.core._seq.Seq[Seq]
pyochain.abc._sequences.PyoSequence[PyoSequence]
pyochain.abc._sequences.PyoReversible[PyoReversible]
pyochain.abc._collection.PyoCollection[PyoCollection]
pyochain.abc._iterable.PyoIterable[PyoIterable]
pyochain.abc._collection.PyoContainer[PyoContainer]
pyochain.abc._collection.PyoSized[PyoSized]
pyochain.abc._mixins.Checkable[Checkable]
pyochain.abc._mixins.Fluent[Fluent]
pyochain.abc._mixins.Pipe[Pipe]
pyochain.abc._mixins.Tap[Tap]
pyochain.abc.constructors.ArgsWrapper[ArgsWrapper]
pyochain.abc.constructors.FromArgs[FromArgs]
pyochain.abc.constructors.FromIter[FromIter]
pyochain.abc.constructors.Wrapper[Wrapper]
pyochain.abc._sequences.PyoSequence --> pyochain.core._seq.Seq
pyochain.abc._sequences.PyoReversible --> pyochain.abc._sequences.PyoSequence
pyochain.abc._iterable.PyoIterable --> pyochain.abc._sequences.PyoReversible
pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
pyochain.abc._collection.PyoCollection --> pyochain.abc._sequences.PyoSequence
pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
pyochain.abc.constructors.ArgsWrapper --> pyochain.core._seq.Seq
pyochain.abc.constructors.FromArgs --> pyochain.abc.constructors.ArgsWrapper
pyochain.abc.constructors.FromIter --> pyochain.abc.constructors.FromArgs
pyochain.abc.constructors.Wrapper --> pyochain.abc.constructors.ArgsWrapper
click pyochain.core._seq.Seq href "" "pyochain.core._seq.Seq"
click pyochain.abc._sequences.PyoSequence href "" "pyochain.abc._sequences.PyoSequence"
click pyochain.abc._sequences.PyoReversible href "" "pyochain.abc._sequences.PyoReversible"
click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
click pyochain.abc._mixins.Checkable href "" "pyochain.abc._mixins.Checkable"
click pyochain.abc._mixins.Fluent href "" "pyochain.abc._mixins.Fluent"
click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
click pyochain.abc.constructors.ArgsWrapper href "" "pyochain.abc.constructors.ArgsWrapper"
click pyochain.abc.constructors.FromArgs href "" "pyochain.abc.constructors.FromArgs"
click pyochain.abc.constructors.FromIter href "" "pyochain.abc.constructors.FromIter"
click pyochain.abc.constructors.Wrapper href "" "pyochain.abc.constructors.Wrapper"
Represent an in memory Sequence.
Implements the Sequence Protocol from collections.abc, as well as PyoSequence.
The underlying data structure is an immutable tuple, hence the memory efficiency is better than a Vec.
Tip
Seq(tuple) is preferred over Seq(list) as this is a no-copy operation (Python optimizes tuple creation from another tuple).
If you have an existing list, consider using Vec instead to avoid unnecessary copying.
If you need immediate iteration anyway, you can directly use Iter instead.
Source code in pyochain/core/_seq.pyi
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
__new__(data=(), /, *more)
__new__() -> Self
__new__(data: Iterable[T]) -> Self
__new__(data: T, /, *more: T) -> Self
Create a new Seq instance.
If no arguments are provided, an empty Seq is created.
Passing a tuple or another Seq will not copy the underlying data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T] | T
|
Initial data to populate the |
()
|
*more
|
T
|
Additional elements to include in the |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
A new |
Example
from pyochain import Seq
py_tuple = (1, 2, 3)
# Create a Seq from an iterable
assert Seq(iter(py_tuple)) == py_tuple
# Create a Seq from individual elements
assert Seq(1, 2, 3) == py_tuple
# Create a Seq from a tuple without copying
seq3 = Seq(py_tuple)
assert id(seq3[0]) == id(py_tuple[0])
# Create an empty Seq
assert Seq() == Seq([]) == Seq(()) == ()
Source code in pyochain/core/_seq.pyi
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
__lt__(value)
Return True if self is less than value, False otherwise.
Raises TypeError if value is not a Seq or a tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
IntoSeq[S]
|
The value to compare against. Can be a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if self is less than value, False otherwise. |
Example
from pyochain import Seq, Err, Ok
s1 = Seq(1, 2, 3)
s2 = Seq(1, 2, 4)
assert s1 < s2
assert not s1 < (1, 2, 3)
try:
res = Ok(s1 < [1, 2, 3])
except TypeError as e:
res = Err(e)
assert res.is_err()
assert res.map_err(lambda e: isinstance(e, TypeError)).unwrap_err()
Source code in pyochain/core/_seq.pyi
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 | |
repeat(n)
Repeat the Seq n times and return a new Seq.
This is equivalent to tuple_1 * n for standard tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of times to repeat the elements. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The new |
Example
from pyochain import Seq
s = Seq(1, 2, 3)
assert s.repeat(2) == Seq(1, 2, 3, 1, 2, 3)
Source code in pyochain/core/_seq.pyi
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
concat(other)
Concatenate another Seq or tuple to self and return a new Seq.
This is equivalent to tuple_1 + tuple_2 for standard tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
IntoSeq[O]
|
The other |
required |
Returns:
| Type | Description |
|---|---|
Seq[T | O]
|
Seq[T | O]: The new |
Example
from pyochain import Seq
s1 = Seq(1, 2, 3)
s2 = (4, 5, 6) # Can also concatenate a standard tuple
s3 = s1.concat(s2)
assert s3 == Seq(1, 2, 3, 4, 5, 6)
Source code in pyochain/core/_seq.pyi
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |