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 -npartial for arbitrary partial application #204

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

Commits on Nov 16, 2016

  1. Add `-npartial' for arbitrary partial application

    Currently, we have `-partial' and `-rpartial' for currying with
    arguments at either the left or the right.
    
    `-npartial' is a generalisation of `-partial' and `-rpartial'. It takes
    an offset N to determine where to put the curried arguments, a function
    FN, and the partially applied ARGS.
    
    ARGS will be spliced in after the Nth element in the additional args. If
    N is negative, -1 is taken to be the final item, -2, the penultimate
    item, etc.
    
    This function satisfies the following laws:
    
      (-npartial 0 ...) ≡ (-partial ...)
      (-npartial -1 ...) ≡ (-rpartial ...)"
    
    E.g.:
      (funcall (-npartial 1 (lambda (a b c) (+ a (* b c))) 5)
          2 3) ;; => 17
      (funcall (-npartial 2 (lambda (a b c d) (+ a (* b c) d)) 3)
          2 4 5) ;; => 19
      (funcall (-npartial -1 #'concat "last " "words.")
          "These " "are " "the ") ;; => "These are the last words."
      (funcall (-npartial 3 (lambda (a b c d e f) (concat a b c d e f "."))
                          "penultimate " "words ")
          "I'll " "put " "the " "here")
      ;; => "I'll put the penultimate words here."
    daantjie committed Nov 16, 2016
    Configuration menu
    Copy the full SHA
    5fee7ca View commit details
    Browse the repository at this point in the history