Skip to content

tracking issue for fallible iterator methods #271

@nxtlo

Description

@nxtlo

Provides iterator methods for items that are fallible.

This allows for useful patterns like:

def writeln(out: IO[str], content: str) -> Result[None, OsError]:
    # handle io read/write that may fail.
    out.write(content + '\n')
    return Ok(None)

data = Vec(["hi", "mother"])
res = data.iter().try_for_each(lambda x: writeln(sys.stderr, x))
assert res.is_ok() # is ok, unless `writeln` causes an Err.

Public API

class Iterator[Item]:
    def try_for_each[E](self, f: Fn[[Item], Result[None, E]]) -> Result[None, E]: ...
    def try_find(self, f: Fn[[Item], Result[Item, None]]) -> Result[Option[Item], None]: ...
    def try_collect(self) -> Option[MutableSequence[Item]] where self yield Option[Item]: ...

Steps / History

  • Implementation: "PR LINK"
  • Adjusted documentation
  • Tested
  • Changelog added

Unresolved Questions

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: A tracking issue for a feature request, i.e: not implemented / a PR.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions