[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Functional composition in ELisp: add `compose' function?
From: |
Stefan Kangas |
Subject: |
Functional composition in ELisp: add `compose' function? |
Date: |
Sun, 14 Feb 2021 19:39:31 -0600 |
I often miss functional composition when I code Emacs Lisp, to say
things like:
(seq-filter (compose #'not #'stringp) '("a" "b" 1 2))
=> (1 2)
Here's an example definition:
(defun compose (&rest fns)
(cl-destructuring-bind (fun . rest) (reverse fns)
(lambda (&rest args)
(seq-reduce (lambda (v f) (funcall f v))
rest
(apply fun args)))))
There is at least some demand for it: the popular third-party library
dash.el provides it[1]. It also exists in Scheme[2] and Common Lisp[3].
Could we add this to Emacs Lisp?
Footnotes:
[1] https://github.com/magnars/dash.el#-compose-rest-fns
[2]
https://www.gnu.org/software/guile/manual/html_node/Higher_002dOrder-Functions.html
[3] https://common-lisp.net/project/cl-utilities/doc/compose.html
- Functional composition in ELisp: add `compose' function?,
Stefan Kangas <=