10000 flow with Config · Issue #5970 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

flow with Config #5970

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

Open
abuseofnotation opened this issue Mar 2, 2025 · 0 comments
Open

flow with Config #5970

abuseofnotation opened this issue Mar 2, 2025 · 0 comments

Comments

@abuseofnotation
Copy link

A helper that I use often in my projects is a function that is like _.flow, but supports an extra argument I call config, which is passed to all functions that I am composing, along with the value.

Reference implementation:

export const flowWithConfig = (...f) => (arg, config)=> f.reduce((res, f) => f(res, config), arg)

Usage:

const foo  = (val, config) => {
  if (config.prop) {
    return doSomething(val)  
  } else {
    return doSomethingElse(val)
  }
}
const bar = (val, config) => someFunction(val, config.prop2)


const composite = flowWithConfig(foo, bar)

composite(val, {prop: true, prop2: false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant
0