1
0
Fork 0
mirror of synced 2024-05-16 02:23:44 +12:00

Use a threaded ->> macro to simplify the code.

This commit is contained in:
Kenneth, Cho Kai Hung 2023-04-02 14:33:26 +01:00 committed by GitHub
parent 1670bf02e5
commit 84d57b2678
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,17 @@
(ns fira-code.files
(:refer-clojure :exclude [find])
(:require
[clojure.java.io :as io]
[clojure.string :as str]))
(:require [clojure.java.io :as io]
[clojure.string :as str]))
(defn- matches-re?
"Returns true if the file name matches the given regular expression."
[re file]
(re-matches re (.getName file)))
(defn- matching-files
"Returns a vector of files in the directory tree rooted at the given path
that match the given regular expression."
[path re]
(->> (path-seq (io/file path))
(filterv #(matches-re? re %))
(sort-by #(.getPath %))))
(defn find [path re]
(->> (file-seq (io/file path))
(next) ;; skip directory itself
(filter #(re-matches re (.getPath %)))
(sort-by #(.getPath %))))