I had never programmed in a functional programming language before. I think that this function has large nesting. Is there way to rewrite it better? I am most worried about the use of "flatten". Is there way to get rid of it? Also, is the indentation correct and does the function name correspond to Clojure naming style?
(defrecord Point [x y])
(def delimiter #" ")
(defn str->cells
"Converts string with cells separated with
delimiter and new lines to Points hash map"
[^String s]
{:pre [(re-matches #"^((?:^|\s)(?:.|\s)(?=\s|$))+$" s)]}
(apply
hash-map
(flatten
(map-indexed
(fn [y line]
(map-indexed
(fn [x value] [(Point. x y) value])
(str/split line delimiter)))
(str/split-lines s)))))
;; Example of use:
(str->cells "1 2\n3") ;; -> {#Point{:x 1, :y 0} "2", #Point{:x 0, :y 0} #Point{:x 0, :y 1} "3"}