getify / fasy

FP iterators that are both eager and asynchronous
MIT License
546 stars 18 forks source link

API question: compose/pipe #4

Closed ducin closed 6 years ago

ducin commented 6 years ago

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?

getify commented 6 years ago

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.

ducin commented 6 years ago

That makes it clear. Thanks Kyle!

czw., 12.04.2018, 16:39 użytkownik Kyle Simpson notifications@github.com napisał:

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 flow(..) and flowRight(..), 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 https://ramdajs.com uses the names compose(..) http://ramdajs.com/docs/#compose and pipe(..) http://ramdajs.com/docs/#pipe.

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. That's why I think both of these utilities are useful in an FP toolbelt.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/getify/fasy/issues/4#issuecomment-380829131, or mute the thread https://github.com/notifications/unsubscribe-auth/AAW48wxgNCOdg2_k3MZCqlQhfjYIG_Nvks5tn2cmgaJpZM4QWd0e .