fsprojects / fsprojects/FSharpPlus
Juxt
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 941
- Forks
- 106
- PR merge metrics
- No merged PRs in 30d
Description
Hello and thank you for creating F#+! I'd like to propose adding juxtapose functions to the Operators module. These functions are defined as follows:
let juxt2 f g x = f x, g x
let juxt3 f g h x = f x, g x, h x
let juxt4 f g h i x = f x, g x, h x, i x
// etc
This function is called juxt in Clojure and the Python toolz library. I believe this function was first introduced by John Backus in his paper called Can programming be liberated from the von Neumann style? where it was called construction.
In Haskell and F#+ there's a similar function called sequence. Unfortunately, it returns a list and not a tuple, forcing all the result types to be the same.
juxt in combination with item and uncurry/uncurryN make point-free programming with tuples easier. Here are some examples:
open FSharpPlus
// Basic examples
let square: float -> float =
juxt2 id id >> uncurry ( * )
let avg: list<float> -> float =
juxt2 List.sum (List.length >> float) >> uncurry (/)
// Grouping and ungrouping tuples
let ``(a,b),c`` (a,b,c) = (a,b),c
let ``~(a,b),c~`` ((a,b),c) = a,b,c
``(a,b),c``(1,2,3) = (juxt2 (juxt2 item1 item2) item3)(1,2,3) // ((1, 2), 3)
``~(a,b),c~``((1,2),3) = (juxt3 (item1 >> item1) (item1 >> item2) item2)((1,2),3) // (1, 2, 3)
Please let me know if this function already exists in F#+ (or F# for that matter) and I missed it. Thank you!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the Operators module and inspect the existing sequence, item, uncurry, and uncurryN functions to match their naming and organization. Implement the proposed juxt2, juxt3, and juxt4 variants, then add coverage for the tuple-producing examples and confirm the project tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100