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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

malaggan
Copy link

@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

See #228.

@eshrh
Copy link

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.

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.

None yet

3 participants