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

'with' optional callback #20987

Closed
wants to merge 1 commit into from
Closed

Conversation

alepeino
Copy link
Contributor

@alepeino alepeino commented Sep 4, 2017

Adds an optional callback as 2nd argument to helper with, to mutate the value before returning it.

If it's preferred not to overload this function, thru may be a good alternative name (same functionality as Lodash function with the same name).

@morloderex
Copy link
Contributor

This sounds a lot like you need to use a tap call instead.

@alepeino
Copy link
Contributor Author

alepeino commented Sep 5, 2017

@morloderex Well, it's not quite the same (that's why I referenced Lodash thru). I basically use tap for two purposes:

  • Side effects:
tap($model, function ($m) { $m->save(); })
  • Objects with an internal state:
tap($model, function ($m) { $m->key = 'value'; })

But tap won't help for cases such as the simple ones I show in the tests. Like, if I don't want to mutate the object state, just get a new state which is a function of the first.

Anyway, this is closed now ¯\_(ツ)_/¯

@alepeino alepeino deleted the with-callback branch October 9, 2017 18:06
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

Successfully merging this pull request may close these issues.

3 participants