Add intermediate helper imalison:compose-2-argspec
This macro is usefule when the first function supplied needs to use special keywords etc.
This commit is contained in:
parent
60404e6f78
commit
656e33a64b
@ -400,19 +400,27 @@ The packages in this section provide no functionality on their own, but provide
|
|||||||
'arg
|
'arg
|
||||||
`(funcall ,(car funcs) (imalison:compose-helper-unary ,(cdr funcs)))))
|
`(funcall ,(car funcs) (imalison:compose-helper-unary ,(cdr funcs)))))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
**** Most performant version supports macros
|
**** A Version Supporting Macros
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defmacro imalison:compose-named-functions (arguments &rest funcs)
|
(defmacro imalison:compose-2 (arguments &rest funcs)
|
||||||
|
(when (numberp arguments)
|
||||||
|
(setq arguments
|
||||||
|
(cl-loop for i from 97 to (+ arguments 96)
|
||||||
|
collect (intern (char-to-string i)))))
|
||||||
|
`(imalison:compose-2-argspec ,arguments ,arguments ,@funcs))
|
||||||
|
|
||||||
|
(defmacro imalison:compose-2-argspec
|
||||||
|
(arguments call-arguments &rest funcs)
|
||||||
"Build a new function with NAME that is the composition of FUNCS."
|
"Build a new function with NAME that is the composition of FUNCS."
|
||||||
`(lambda ,arguments
|
`(lambda ,arguments
|
||||||
(imalison:compose-named-functions-helper ,funcs ,arguments)))
|
(imalison:compose-2-helper ,funcs ,call-arguments)))
|
||||||
|
|
||||||
(defmacro imalison:compose-named-functions-helper (funcs arguments)
|
(defmacro imalison:compose-2-helper (funcs arguments)
|
||||||
"Builds funcalls of FUNCS applied to the arg."
|
"Builds funcalls of FUNCS applied to the arg."
|
||||||
(if (equal (length funcs) 1)
|
(if (equal (length funcs) 1)
|
||||||
`(,(car funcs) ,@arguments)
|
`(,(car funcs) ,@arguments)
|
||||||
`(,(car funcs)
|
`(,(car funcs)
|
||||||
(imalison:compose-named-functions-helper ,(cdr funcs) ,arguments))))
|
(imalison:compose-2-helper ,(cdr funcs) ,arguments))))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
*** Prefix Alternatives
|
*** Prefix Alternatives
|
||||||
Prefix alternatives is a macro that builds a function that selects one of a collection of functions that are provided to the macro based on the value of the prefix argument.
|
Prefix alternatives is a macro that builds a function that selects one of a collection of functions that are provided to the macro based on the value of the prefix argument.
|
||||||
@ -608,7 +616,7 @@ Get route information
|
|||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defun imalison:muni-get-route-ids (route-name &optional direction)
|
(defun imalison:muni-get-route-ids (route-name &optional direction)
|
||||||
(delete-dups
|
(delete-dups
|
||||||
(mapcar (imalison:compose imalison:car-intern 'intern 'car)
|
(mapcar (imalison:compose-2 1 intern car)
|
||||||
(s-match-strings-all
|
(s-match-strings-all
|
||||||
"^\\([[:digit:]]\\{1,10\\}\\)"
|
"^\\([[:digit:]]\\{1,10\\}\\)"
|
||||||
(shell-command-to-string
|
(shell-command-to-string
|
||||||
|
Loading…
Reference in New Issue
Block a user