Skip to content

Add juxt for applying multiple functions to the same arguments#263

Merged
phanan merged 1 commit intomainfrom
feature/juxt
Mar 21, 2026
Merged

Add juxt for applying multiple functions to the same arguments#263
phanan merged 1 commit intomainfrom
feature/juxt

Conversation

@phanan
Copy link
Collaborator

@phanan phanan commented Mar 21, 2026

Summary

  • Adds juxt(callable ...$functions), which returns a new function that applies each given function to the same arguments and returns an array of results
  • Inspired by Clojure's juxt
  • Related to the existing converge(), which additionally passes results through a converging function. juxt is the simpler case where you just want the array of results.
use function Functional\juxt;

$getStats = juxt('min', 'max');
$getStats(3, 1, 5, 2); // [1, 5]

$transform = juxt('strtoupper', 'strtolower', 'strrev');
$transform('Hello'); // ['HELLO', 'hello', 'olleH']

Test plan

  • Unit tests covering multiple functions, multiple arguments, array functions, closures, no functions, and single function (6 tests, 6 assertions)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@phanan phanan merged commit 63aaefd into main Mar 21, 2026
10 checks passed
@phanan phanan deleted the feature/juxt branch March 21, 2026 18:59
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.

1 participant