Out of curiosity, could you share an example of how this compares to Clojure or Scala? I am not familiar with either.
(def articles
[{:title "title1" :author "author1" :tags #{:Java :t2 :t3}}
{:title "title2" :author "author1" :tags #{:Jvxa :t2 :t3}}
{:title "title3" :author "author3" :tags #{:Java :t3}}])
;; find the first article in the collection that has the tag “Java”.
(first (filter #(contains? (:tags %) :Java) articles))
;; ==> {:tags #{:t2 :Java :t3}, :title "title1", :author "author1"}
;;get all the elements that match instead of just the first
(filter #(contains? (:tags %) :Java) articles)
;; ==> ({:tags #{:t2 :Java :t3}, :title "title1", :author "author1"}
{:tags #{:Java :t3}, :title "title3", :author "author3"})
;;group all the articles based on the author.
(group-by :author articles) ;; cheating?
;; ==> {"author1"
[{:tags #{:t2 :Java :t3}, :title "title1", :author "author1"}
{:tags #{:Jvxa :t2 :t3}, :title "title2", :author "author1"}],
"author3"
[{:tags #{:Java :t3}, :title "title3", :author "author3"}]}
;;find all the different tags used in the collections
(apply clojure.set/union (map :tags articles))
;; ==> #{:Jvxa :t2 :Java :t3} (group-by :author articles)
groupBy ((==) `on` author) articles
What's wrong with cheating? :P def topJavaArticle(articles:List[Article]) = articles.find(_.tags.contains("Java"))
def javaArticles(articles:List[Article]) = articles.filter(_.tags.contains("Java"))
def byAuthor(articles:List[Article) = articles.groupBy(_.author)
0: https://news.ycombinator.com/item?id=8874785