Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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."
- Loading branch information