Homework 06 Shamshurin Ivan#12
Conversation
otus-06/src/otus_06/homework.clj
Outdated
| (string/split line #"\|")) | ||
|
|
||
| (defn- fmt-line [line] | ||
| (-> (split-line line) |
There was a problem hiding this comment.
Если тред-фёст макрос, то почему бы не всё через него? )
(-> line split-line rest vec)
otus-06/src/otus_06/homework.clj
Outdated
| vec)) | ||
|
|
||
| (defn- print-table [fmt-fn name] | ||
| (let [tables {:customer "resources/homework/cust.txt" |
There was a problem hiding this comment.
Локальная привязка внутри функции? ) Не верю )
| (println (fmt-fn lines)))))) | ||
|
|
||
| (defn- table-value [table-key id & [value-col id-col]] | ||
| (with-open [rdr (io/reader (tables table-key))] |
There was a problem hiding this comment.
Правильно не верил, здесь обращение к несуществующей таблез. И если бы в вашей ИДЕ стоял линтер (самостоятельно, или как часть плагина), он бы подчеркнул красным )
There was a problem hiding this comment.
Делал ночью, не допушил эту правку. Использую емакс и practicalli, там всё настроено
|
|
||
| (defn- table-value [table-key id & [value-col id-col]] | ||
| (with-open [rdr (io/reader (tables table-key))] | ||
| (loop [lines (line-seq rdr)] |
There was a problem hiding this comment.
Имхо нагляднее и короче через функции на сиквенсах - filter, some etc.
|
|
||
| (defn- fmt-sales-line [line] | ||
| (let [line-vec (fmt-line line) | ||
| [customer-id product-id count] line-vec] |
There was a problem hiding this comment.
Можно сразу (let [[customer-id product-id count] (fmt-line line)]
| :product 1} | ||
| id (table-value table-key name 0 1)] | ||
| (with-open [rdr (io/reader (tables :sales))] | ||
| (loop [lines (line-seq rdr) |
There was a problem hiding this comment.
reduce имхо тут бы смотрелся гораздо уместнее )
| ")) | ||
|
|
||
| (defn- make-action [input] | ||
| (cond (= input "1") (do (print-table fmt-line :customer) |
|
|
||
| (defn- make-action [input] | ||
| (cond (= input "1") (do (print-table fmt-line :customer) | ||
| true) |
There was a problem hiding this comment.
true во всех кейсах смотрится немного искусственно, можно nil по дефолту если всё ок, и true наоборот, если надо прекращать безобразие )
| (defn -main [] | ||
| (print-menu) | ||
| (loop [num (read-line)] | ||
| (and (make-action num) |
There was a problem hiding this comment.
Понтово, and без ифов/кейсов, функциональный паттерн )
| (= input "6") nil | ||
| :else true)) | ||
|
|
||
| (defn -main [] |
There was a problem hiding this comment.
Приятная мелочь, все приватные функции неймспейса через defn-, хороший стиль
No description provided.