Skip to content

Add the branching arrows -<, -<<, --<, and -as-<. (resubmitted)#280

Open
malaggan wants to merge 1 commit intomagnars:masterfrom
malaggan:master
Open

Add the branching arrows -<, -<<, --<, and -as-<. (resubmitted)#280
malaggan wants to merge 1 commit intomagnars:masterfrom
malaggan:master

Conversation

@malaggan
Copy link
Copy Markdown

@malaggan malaggan commented Jan 5, 2019

Note: I had to resubmit a new pull request instead of #279 because the previous pull request cannot be reopened.

Add parallel-threading macros inspired by https://github.com/rplevy/swiss-arrows. The general idea is the to complement the existing threading macros, which apply forms in sequence, to provide similar macros that apply forms in parallel.

For example: (-< 3 list 1+ 1- (* 2)) will produce (4 2 6), and (-< 3 + 1+ 1- (* 2)) will produce 12. The syntax is similar to the sequential threading macros (->, ->>, etc.) except that an extra parameter is needed: the "collector" that will take the forms as arguments. This choice was made, instead of returning a list, to allow for short-circuiting special forms like and to be used.

The use case I've personally encountered that motivated me to implement this was the need to pass the same value to several predicates and combine these predicates using and:

(and (listp element)
        (-> element length (>= 2))
        (-> element car atom)
        (-> element cadr alistp)
       element)

could be written as:

(-< element and
      listp
      (-> length (>= 2))
      (-> car atom)
      (-> cadr alistp)
      identity))

@alphapapa
Copy link
Copy Markdown

See #228.

@eshrh
Copy link
Copy Markdown

eshrh commented Jun 29, 2022

Is there any update on getting this merged? I like these macros a lot, but I have to include them in my config manually...

Honestly, though, I'm not a huge fan of including the "collector" as the second argument. I think it's better handled by a normal reduction, like in the implementations given by alphapapa which match swiss-arrows.

@basil-conto basil-conto added the enhancement Suggestion to improve or extend existing behavior label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Suggestion to improve or extend existing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants