-
-
Save noidi/60b7456d27c3bbf22eb2 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
;;; Changes: | |
;;; - Annotate the parameter of the lambda given to filter. This was the cause of the error. | |
;;; - Change the last parameter of lookup-by from Seq to Seqable to allow it to work with vectors. | |
;;; - Replace (IFn [a -> b]) with [a -> b]. They're equivalent. | |
(t/ann lookup-by (t/All [a b] | |
[b [a -> b] (t/Option (t/Seqable a)) -> (t/Option a)])) | |
(defn lookup-by | |
"Convenience filter. Returns the first item in coll where (= value (lookup-fn item))" | |
[value lookup-fn coll] | |
(first (filter (t/fn _ [x :- a] | |
(= value (lookup-fn x))) | |
coll))) | |
; Example | |
(lookup-by "Kris" :name [{:name "foo"} {:name "Kris"} {:name "bar"}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 Thanks dude!