LoginSignup
5
5

More than 5 years have passed since last update.

Emacs Lisp の reduce

Posted at

毎度使い方忘れるのでメモ。

(require 'cl-seq)

;; (or (or (or "a" "b") "c") "d") と同じ
(reduce (lambda (result item) (or result item))
        '("a" "b" "c" "d"))
;; => "a"

;; フィルタ関数を順番にかける
(reduce (lambda (res fun) (funcall fun res))
        '(;; 元になる文字列
          "hoge"

          ;; o を a に置換 => "hage"
          (lambda (str) (replace-regexp-in-string "o" "a" str))

          ;; 先頭文字を大文字に変換 => "Hage"
          (lambda (str) (capitalize str))

          ;; 同じ文字列を2回繰り返す => "HageHage"
          (lambda (str) (concat str str))))
;; => "HageHage"
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5