Last active
August 29, 2015 14:06
-
-
Save minimal/d432e2444f652b461671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ann get-from-state | |
(t/All [a b] | |
[(t/Option (t/Map b a)) (t/Option (t/Coll b)) -> (t/Option a)])) | |
(defn get-from-state [state keys] | |
(t/loop [acc :- (t/Option a) nil | |
keys :- (t/Option (t/Coll b)) keys] | |
(if-not (and state (seq keys)) | |
acc | |
(recur (get state (first keys)) | |
(rest keys))))) | |
(ann get-from-state2 | |
[(t/Option (t/Map t/Any t/Any)) | |
(t/Option (t/Coll t/Any)) -> (t/Option t/Any)]) | |
(defn get-from-state2 [state keys] | |
(t/loop [acc :- (t/Option Any) nil | |
keys :- (t/Option (t/Coll t/Any)) keys] | |
(if-not (and state (seq keys)) | |
acc | |
(recur (get state (first keys)) | |
(rest keys))))) | |
(ann get-from-state-orig | |
[(U t/Any (t/Map t/Any t/Any)) | |
(t/Option (t/Coll t/Any)) -> (t/Option t/Any)]) | |
(defn get-from-state-orig [state keys] | |
(if (or (nil? state) (empty? keys) (not (map? state))) | |
state | |
(recur (get state (first keys)) | |
(rest keys)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment