Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns for-repl.core
- (:require [clojure.core.typed :refer [defn ann ann-record let cf doseq HMap Any U Seq]]))
- (ann ^:no-check clojure.core/assoc! [Any Any Any Any * -> nil])
- (ann ^:no-check clojure.core/transient [(HMap :complete? true) -> Any])
- (ann ^:no-check clojure.core/persistent! [Any -> (HMap :optional {:name String :weight String})])
- (ann-record Human [name :- String weight :- Long])
- (defrecord Human [name weight])
- (defn human [name :- String weight :- Long] :- Human
- (Human. name weight))
- (defn validate-human-args [name :- (U String nil) weight :- (U String nil)] :- (HMap :optional {:name String :weight String} :complete? true)
- (let [errors (transient {})]
- (when-not name
- (assoc! errors :name "Name there must be"))
- (when-not weight
- (assoc! errors :weight "Weight there must be"))
- (persistent! errors)))
- (defn parse-long [str :- String] :- Long
- (Long/parseLong str))
- (defn -main [& args :- String *] :- nil
- (let [[name weight] args
- errors (validate-human-args name weight)]
- (if (seq errors)
- (doseq [[field :- Symbol message :- String] errors]
- (println message))
- (when (and name weight)
- (try
- (println (human name (parse-long weight)))
- (catch NumberFormatException e
- (println "Weight must be integer!")))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement