Ancestors

Written by dseguy on 2025-01-03 at 17:43

So, #PHP has fluent interfaces, but it also can do fluent functions: functions that can be chain called.

As usual, it works but it is a tad cumbersome.

[#]phptip #phptrick

https://php-tips.readthedocs.io/en/latest/tips/fluent_function.html

=> View attached media

=> More informations about this toot | More toots from dseguy@phpc.social

Written by Ben Ramsey on 2025-01-03 at 20:09

@dseguy Do you have any thoughts on use-cases for this approach that a recursive function wouldn’t solve? Getting back the function itself doesn’t seem terribly useful, to me. Maybe if the input params are passed by reference?

=> More informations about this toot | More toots from ramsey@phpc.social

Written by dseguy on 2025-01-03 at 20:56

@ramsey I don't see anything practical for this: the result extraction is way too cumbersome and un-modern.

Although, the chained calls looks quite nice, and 'fluent function' sounds also terrific.

And, of course, blame @heiglandreas (for inspiration).

=> More informations about this toot | More toots from dseguy@phpc.social

Written by Gina Peter Banyard on 2025-01-03 at 21:00

@dseguy @ramsey @heiglandreas Changing f($v1, $v2, $v3) into f($v1)($v2)($v3) is really just currying.

=> More informations about this toot | More toots from Girgias@phpc.social

Written by dseguy on 2025-01-03 at 21:02

@Girgias @ramsey @heiglandreas Now, is that good or bad? (Asking for a friend)...😇

=> More informations about this toot | More toots from dseguy@phpc.social

Written by Gina Peter Banyard on 2025-01-03 at 21:03

@dseguy @ramsey @heiglandreas It's common in functional programming or if you want to work with higher order functions. It's neither good or bad, just a tool :)

=> More informations about this toot | More toots from Girgias@phpc.social

Toot

Written by Pol Dellaiera on 2025-01-03 at 21:55

@Girgias @dseguy @ramsey @heiglandreas If you want some real, this library is full of currying https://github.com/loophp/collection/

If I had to redo it today, I would do it differently. Not that it was not convenient, just that it doesn't really bring some added value.

=> More informations about this toot | More toots from Pol@mathstodon.xyz

Descendants

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113766649925393022
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
303.796022 milliseconds
Gemini-to-HTML Time
1.212721 milliseconds

This content has been proxied by September (ba2dc).