Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
::: iterum.Nil
::: iterum.nil

::: iterum.is_some
::: iterum.is_nil

::: iterum.ExpectNilError
::: iterum.UnwrapNilError

Expand Down
14 changes: 13 additions & 1 deletion src/iterum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
Zip,
iterum,
)
from ._option import ExpectNilError, Nil, Option, Some, Swap, UnwrapNilError, nil
from ._option import (
ExpectNilError,
Nil,
Option,
Some,
Swap,
UnwrapNilError,
is_nil,
is_some,
nil,
)
from ._ordering import Ordering
from ._seq import InfSeq, Seq, seq

Expand All @@ -42,6 +52,8 @@
"nil",
"ExpectNilError",
"UnwrapNilError",
"is_nil",
"is_some",
# Ordering
"Ordering",
# special Iterum implementations
Expand Down
15 changes: 10 additions & 5 deletions src/iterum/_diterum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from abc import abstractmethod
from collections.abc import Callable, Sequence
from typing import override

from ._iterum import Iterum, T_co, U
from ._iterum import Iterum, T_co
from ._option import Option, Some, nil


Expand Down Expand Up @@ -202,7 +201,7 @@ def rfind(self, predicate: Callable[[T_co], object], /) -> Option[T_co]:
"""
return self.rev().find(predicate)

def rfold(self, init: U, f: Callable[[U, T_co], U], /) -> U:
def rfold[U](self, init: U, f: Callable[[U, T_co], U], /) -> U:
"""
A diterum method that reduces the diterum's elements to a single,
final value, starting from the back.
Expand Down Expand Up @@ -241,7 +240,7 @@ def rfold(self, init: U, f: Callable[[U, T_co], U], /) -> U:
"""
return self.rev().fold(init, f)

def try_rfold(
def try_rfold[U](
self,
init: U,
f: Callable[[U, T_co], U],
Expand Down Expand Up @@ -278,12 +277,15 @@ class Rev(Diterum[T_co]):
def __init__(self, __x: Diterum[T_co] | Sequence[T_co]) -> None:
self._x = __x if isinstance(__x, Diterum) else diterum(__x)

@override
def next(self) -> Option[T_co]:
return self._x.next_back()

@override
def next_back(self) -> Option[T_co]:
return self._x.next()

@override
def len(self) -> int:
return self._x.len()

Expand Down Expand Up @@ -331,6 +333,7 @@ def __init__(self, __seq: Sequence[T_co], /) -> None:
self._front = 0
self._back = len(__seq) - 1

@override
def next(self) -> Option[T_co]:
"""
Returns the next value in the sequence from the front if present,
Expand All @@ -354,6 +357,7 @@ def next(self) -> Option[T_co]:
self._front += 1
return Some(nxt)

@override
def next_back(self) -> Option[T_co]:
"""
Returns the next value in the sequence from the back if present,
Expand All @@ -377,6 +381,7 @@ def next_back(self) -> Option[T_co]:
self._back -= 1
return Some(nxt)

@override
def len(self) -> int:
"""
Returns the remaining length of the sequence.
Expand Down
Loading
Loading