我正尝试在破折号中创建一个合成,它执行以下操作 -分成几行 -删除空行 -保持以“ N”开头的行 -返回文件扩展名
但是下面的代码感觉很笨拙-想知道是否有人可以提供帮助 简化/重写。
(let ((line-sep "\\\n")
(new-ind "^N ")
(sample-output "
N /dir1/file1.el
N /dir1/file2.dot
/dir1/file3.py
/dir1/file4.sql"))
(funcall
(-compose
(-partial '-map (lambda(x) (file-name-extension (nth 1 (split-string x)))))
(-partial '-filter (-partial 'string-match-p new-ind)) ; keep lines starting w/"N"
(-partial '-filter (lambda(x) (> (length x) 0))) ; remove empty lines
(-partial (-flip 'split-string) line-sep)) ; split into lines
sample-output))
答案 0 :(得分:0)
弄弄了它之后,看来compose流水线只有在所有函数都采用相同类型的参数时才能很好地工作。我这样重写它,看起来更合适;想听听评论。
(let* ((line-sep "\\\n")
(lexical-binding t)
(new-ind "^\\s-*N ")
(sample-output "
N /dir1/file1.el
N /dir1/file2.dot
/dir1/file3.py
/dir1/file4.sql")
(lines (split-string sample-output "\\\n")))
(-annotate
'file-name-extension
(-map
(-compose
(-partial 'nth 2)
(-partial (-flip 'split-string) "\\s-+"))
(--filter
(string-match-p "^\\s-*N " it)
lines))))