假设我有一个向量["a""b""c""a""a""b"]
。如果给定一个序列 ["a""b"]
,我该如何删除该序列的所有实例(按顺序)?在这里,结果将只是 ["c""a"]
。
最佳答案
如果预先知道需要删除的序列,core.match
可能对您的任务有用:
(require '[clojure.core.match :refer [match]])
(defn remove-patterns [seq]
(match seq
["a" "b" & xs] (remove-patterns xs)
[x & xs] (cons x (remove-patterns xs))
[] ()))
(remove-patterns ["a" "b" "c" "a" "a" "b"]) ;; => ("c" "a")
关于algorithm - 如何在 Clojure 中删除向量中的顺序匹配项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36359849/