Clojure

Notes on Clojure.

Reference

Concatenating strings

(require '[clojure.string :as string])

(string/join ["foo" "bar"])

List files recursively

Clojure

To list files recursively in Clojure1

(file-seq "/etc")

Babashka

If using Babashka, the following works:

(file-seq (clojure.java.io/file "/etc"))

Filter by extension

(filter #(.endsWith (.toString %) ".conf") 
	(file-seq "/etc"))

Get home directory

(def home (System/getProperty "user.home"))

Filter collection

Use the syntax (filter predicate collection). For instance, to filter a collection of strings that end with bar, do:

(def strings ["Foobar" "Barfoo" "Foobaz" "Barbar"])

(filter
 (fn [s] (clojure.string/ends-with? s "bar")) strings)

  1. Compare with the Java version. ↩︎