Skip to content

Add a way to have type safe function pipelines with unlimited number of functions #253

@travis-leith

Description

@travis-leith

Is your feature request related to a problem? Please describe.
I am in a situation where I want to pipeline more than 9 functions and I want them type checked with Pylance.
Currently this is not possible

Describe the solution you'd like
I would like to be able to do this with any number of functions.

Describe alternatives you've considered
This is what I am using instead

T = TypeVar("T")
U = TypeVar("U")


class Pipe(Generic[T]):
    def __init__(self, value: T) -> None:
        self.value: T = value

    def __or__(self, func: Callable[[T], U]) -> "Pipe[U]":
        return Pipe(func(self.value))

    def unwrap(self) -> T:
        return self.value

Additional context
I realize the package docs indicate they do not like | overloading, but I do not know of any other way of achieving this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions