getify / fasy

FP iterators that are both eager and asynchronous

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API question: compose/pipe

ducin opened this issue · comments

Hi again Kyle :)

I've got a question about API.compose/API.pipe. The only difference I see between them is that the former is right-to-left, whereas the latter is left-to-right. Not sure what is the standard for composing functional APIs (if you know, I'd appreciate a link/resource), I thought that you write functions left-to-right and it is the internal implementation that reverses it.

Anyway, I found it somehow confusing what fasy offers right now: compose & pipe differ only in order and the names are different and logically they seem to be the same, somehow. I find reduce/reduceRight straightforward. Do you think compose/composeRight would make sense?

Sorry for never responding here.

I understand the desire to stick with the naming convention of reduce(..) / reduceRight(..), but even those names have differences in various different FP libs. Sometimes they're referred to foldL(..) and foldR(..), and in other cases, other names.

The names compose(..) and pipe(..) are fairly standard FP names for these operations, and indeed the only difference is the order of processing the list of functions. For example, Ramda uses the names compose(..) and pipe(..). And lodash/fp aliases pipe(..) to its flow(..) and compose(..) to its flowRight(..).

Moreover, the reason for both of these utilities to exist is that there are times when it's more convenient to compose functions from right-to-left and other times when it's nicer to specify them left-to-right. It's long established that both of these utilities are useful in the FP toolbelt.