Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns playground.core
- (:require [try-let :refer [try-let]])
- (:gen-class))
- (defn opt [f] (fn [x] (try-let [res (f x)]
- res
- (catch Exception ex nil))))
- (defn safe_inv [x] ((opt (partial / 1)) x))
- (defn safe_sqrt [x] ((opt #(Math/sqrt %)) x))
- (defn compose [f g]
- (fn [x]
- (if-let [res (f x)]
- (g res)
- "Fail")))
- (defn -main
- []
- (println (map #((compose safe_inv safe_sqrt) %) [4 3 2 1 0 -1 -2]))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement