Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support falsy paramaters ? #14

Open
illiaChaban opened this issue Apr 3, 2024 · 1 comment
Open

Support falsy paramaters ? #14

illiaChaban opened this issue Apr 3, 2024 · 1 comment

Comments

@illiaChaban
Copy link

I love your pipe-ts package, thanks for creating that! There was one use case that I wish it supported - falsy parameters

Example

const data = pipeWith(   
  apiData,   
  ...,  
  someOtherData && doSomethingToData(someOtherData)
)

In theory, some helper function like iif(condition, doThis, doThat?) could be used, but it doesn't work well in cases where condition part needs to be used to compose doThis function.

I have made it working locally with full TS inference and I was wondering if you think it could be a useful update to this package. If so, i could put up a pull request

If you'd rather keep the original package simple, I could fork your package and make my own

Thanks!

@illiaChaban
Copy link
Author

illiaChaban commented Apr 3, 2024

Here's maybe a better example

const finalData = pipeWith(array1, array2 && concat(array2))

Without using function approach & followiing immutability principles, this would look like this

const finalData = [...array1]
if (array2) finalData.push(...array2)

// Or without unnecessarily cloning the first array

let finalData = array1
if (array2) finalData = [...finalData, ...array2]

IMO the first example is a lot more readable, shorter and there's no mutable / immutable (+ const / let) overhead

Or another one

const data = pipeWith(array, featureEnabled && addSomethingToTheList)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant