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-<. #279

Closed
wants to merge 1 commit into from
Closed

Add the branching arrows -<, -<<, --<, and -as-<. #279

wants to merge 1 commit into from

Conversation

malaggan
Copy link

@malaggan malaggan commented Dec 31, 2018

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

#228

@malaggan
Copy link
Author

#228

Thank you for pointing me to this. I was not aware an issue was already open. How do you propose we proceed now?

@alphapapa
Copy link

Well, as I said in the issue, I'm in favor of them. It looks like you've done a good and thorough job in this patch. But it's up to the Dash maintainers whether to accept it.

@malaggan malaggan closed this Jan 4, 2019
@alphapapa
Copy link

@malaggan D: Did you change your mind? I was looking forward to being able to use these.

@malaggan
Copy link
Author

malaggan commented Jan 4, 2019

@alphapapa No, I haven't changed my mind. I am committed to seeing this PR through and to addressing any concerns raised. I take my contributions very seriously, and I am thankful for the time everyone who reviews/comments on it invests. Kindly accept my apologies for the abrupt temporary closure of this PR. I had to temporarily close it because I remembered that I had to do something (non-technical) first. I will reopen the PR as soon as I can.

(-partition-after-pred #'oddp '()) ;; => '()
(-partition-after-pred #'oddp '(1)) ;; => '((1))
(-partition-after-pred #'oddp '(0 1)) ;; => '((0 1))
(-partition-after-pred (function oddp) '()) ;; => '()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of these changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #280.

(-partition-before-pred #'oddp '()) ;; => '()
(-partition-before-pred #'oddp '(1)) ;; => '((1))
(-partition-before-pred #'oddp '(0 1)) ;; => '((0) (1))
(-partition-before-pred (function oddp) '()) ;; => '()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of these changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #280.

@@ -2658,7 +2742,7 @@ expects a list with n items as arguments

```el
(-map (-applify '+) '((1 1 1) (1 2 3) (5 5 5))) ;; => '(3 6 15)
(-map (-applify (lambda (a b c) `(,a (,b (,c))))) '((1 1 1) (1 2 3) (5 5 5))) ;; => '((1 (1 (1))) (1 (2 (3))) (5 (5 (5))))
(-map (-applify (lambda (a b c) (\` ((\, a) ((\, b) ((\, c))))))) '((1 1 1) (1 2 3) (5 5 5))) ;; => '((1 (1 (1))) (1 (2 (3))) (5 (5 (5))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of these changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #280.

Note: these changes were auto generated by create-docs.sh.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, but I don't know why. I think your emacs version and the previous person's who run that are different and that makes the inconsistencies.

We really should build the docs on the CI env.

@@ -1554,6 +1554,69 @@ and when that result is non-nil, through the next form, etc."
(--> ,result ,form))
,@more))))

(defmacro ---thread-each-and-collect (op x collector &optional forms)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use dash-- prefix for private functions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #280.

"
(let ((value (make-symbol "value")))
`(let ((,value ,x))
(,collector ,@(--map (list op value it)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't value be unquoted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole sexp is unquoted: ,@(--map (list op value....

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course :) 👍

@malaggan
Copy link
Author

malaggan commented Jan 5, 2019

This pull request cannot be reopened, unfortunately, so I had to resubmit it (after all the comments here were addressed) at #280. Apologies for the inconvenience.

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