Hacker News new | ask | show | jobs
by aaroniba 4878 days ago
The equivalent clojure code would be:

    (defn f [a b]
      (let [res (join "," (sort (distinct (mapcat keys [a b]))))]
        (if (empty? res) "<none>" res)))
Also I'm not a Scala expert, but I think you want .keySet instead of .keys, otherwise they won't be unique, right?
1 comments

> you want .keySet instead of .keys, otherwise they won't be unique, right?

     scala> val p = Map(1->4,5->3)
     scala> p.keys
     res0: Iterable[Int] = Set(1, 5)
     scala> p.keySet
     res1: scala.collection.immutable.Set[Int] = Set(1, 5)
     scala> p.keys++p.keys
     res2: Iterable[Int] = Set(1, 5)
     scala> p.keySet++p.keySet
     res3: scala.collection.immutable.Set[Int] = Set(1, 5)