Carp/core/Filepath.carp
2018-09-25 16:20:59 +02:00

13 lines
336 B
Plaintext

(defmodule Filepath
(use Array)
(doc dir-from-path "Removes the file-name part of a path to a file.")
(defn dir-from-path [path]
(let [segments (split-by path &[\/])
n (dec (length &segments))
without-last (prefix-array &segments n)]
(concat &(copy-map (fn [s] (str* s "/")) &without-last))))
)