PyoSequence
Bases: ,
Base trait for eager pyochain sequences.
PyoSequence[T] is the shared trait for concrete, eager sequence-like
collections: Seq and Vec.
It extends PyoCollection[T] and collections.abc.Sequence[T].
This is equivalent to subclassing collections.abc.Sequence[T] (this trait
already does), meaning any concrete subclass must implement the required
Sequence dunder methods:
__getitem____len____contains____iter__
On top of the standard Sequence protocol, it provides the additional
pyochain API (from PyoCollection, Pipeable, Checkable, plus any helpers defined here).
Source code in src/pyochain/traits/_iterable.py
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 | |
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
|
|
The index or slice of the element to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
|
Option[T] | Option[Sequence[T]]: |
Example:
>>> import pyochain as pc
>>> pc.Seq([10, 20, 30]).get(1)
Some(20)
>>> pc.Seq([10, 20, 30]).get(5)
NONE
Source code in src/pyochain/traits/_iterable.py
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 | |
is_distinct()
Return True if all items of the Sequence are distinct.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
|
True if all items are distinct, False otherwise. |
>>> import pyochain as pc
>>> pc.Seq([1, 2]).is_distinct()
True
Source code in src/pyochain/traits/_iterable.py
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 | |
rev()
Return an Iterator with the elements of the Sequence in reverse order.
Returns:
| Type | Description |
|---|---|
|
Iter[T]: An |
Example:
>>> import pyochain as pc
>>> pc.Seq([1, 2, 3]).rev().collect()
Seq(3, 2, 1)
Source code in src/pyochain/traits/_iterable.py
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 | |