pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.71k stars 263 forks source link

Add composition as an operator via a new `composable` class #531

Closed ruancomelli closed 1 year ago

ruancomelli commented 2 years ago

Overview

Add a new composable class for functions that can be composed via the pipe operator. This idea originated from and was discussed in https://github.com/pytoolz/toolz/issues/523.

In this implementation, I decided not to include any type-annotations. This is because most of (all?) the project lacks type-annotations. Adding such annotations is probably a PR of its own.

Future work

  1. Make other tools classes inherit from composable as well, like curry, juxt, and excepts, as suggested in https://github.com/pytoolz/toolz/issues/523#issuecomment-1037008717.
  2. We can probably make something very similar for the pipe function by creating a pipeable class.
ruancomelli commented 2 years ago

Converted to draft because of https://github.com/pytoolz/toolz/issues/523#issuecomment-1163861266. We should first settle on the exact desired behavior before having this PR merged.

ruancomelli commented 1 year ago

I'll close this PR for now since it is unclear how to proceed (see discussion at https://github.com/pytoolz/toolz/issues/523). If it becomes relevant again, we can either open a new PR or reopen it.