Created
May 1, 2016 17:24
-
-
Save timmc/de9251eb5343bcc72ef20347ef24026c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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