Skip to content

Instantly share code, notes, and snippets.

@timmc
Created May 1, 2016 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/de9251eb5343bcc72ef20347ef24026c to your computer and use it in GitHub Desktop.
Save timmc/de9251eb5343bcc72ef20347ef24026c to your computer and use it in GitHub Desktop.
(defn- ^File path-cat
"Concatenate a path onto a file, with the same semantics as 'file."
[f p]
{:pre [f, p], :post [(cast File %)]}
(let [f2 (io/file p)]
(if (.isAbsolute f2) (io/file p) (io/file f p))))
(defn ^File file
"Concatenate one or more paths. Absolute paths overrule all previous paths.
Concatenating a/b/c with /d/e/f results in /d/e/f."
[path & more]
{:pre [path], :post [(cast File %)]}
(let [f (io/file path)]
(if (empty? more) (io/file f) (reduce path-cat f more))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment