lo icon indicating copy to clipboard operation
lo copied to clipboard

Doesn't this need a PIPE function to chain ops?

Open effinsky opened this issue 3 years ago • 3 comments

In Ramda, for instance, we have a pipe func to enable chaining operations on collections etc. Seems quite a boon it would be to have it here in LO --

Screenshot 2023-01-06 at 09 51 26

effinsky avatar Jan 06 '23 08:01 effinsky

@effinsky I thought about the same thing!

I just did a draft implementation of what I thought that a Compose and a Pipe functions would look like. You can see it here if you'd like: https://github.com/GCrispino/lo/blob/compose/func.go#L43

These functions receive just two functions as arguments, which is not exactly what happens in their counterparts in Ramda/Lodash, where you can pass a variadic number of functions. I think this couldn't be replicated in Golang in a type safe way, but something like the PartialN functions and create ComposeN and PipeN functions.

If this sounds interesting to the maintainer I'd be happy to create a pull request with these changes.

GCrispino avatar Jan 10 '23 02:01 GCrispino

This would be nice, since at the moment things can get really cumbersome with needless intermediate variables for collections etc between outputs that should naturally flow into further ops as inputs.

effinsky avatar Mar 09 '23 08:03 effinsky

@effinsky FYI, went ahead and created #325 to address this 👍🏼

GCrispino avatar Mar 12 '23 16:03 GCrispino

Thanks for the proposal.

We added support for Go iterators in lo >= 1.52. I also implemented a dedicated Go package for reactive programming: https://github.com/samber/ro

Further discussion will take place there.

samber avatar Oct 14 '25 16:10 samber