3 ms·
Golfing it for Haskell go :: (Show k, Eq k) => Map k v -> Map k v -> String go m1 m2 = map show >>> sort >>> intersperse ", " >>> mconcat >>> orNone
by tel 14y ago
Golfing it for Haskell
go :: (Show k, Eq k) => Map k v -> Map k v -> String
go m1 m2 = map show >>> sort >>> intersperse ", " >>> mconcat >>> orNone
$ keys m1 ++ keys m2
where orNone [] = "<none>"
orNone e = e
- evincarofautumn 14y agoSome quick tips. “intersperse ", " >>> mconcat” is “intercalate ", "”, and I would prefer “.” to “>>>”. Even though left-to-right composition reads better to me, right-to-left is the style. Gratuitious pointfree version (imports omitted): go :: (Show k, Eq k) => Map k v -> Map k v -> String go = orNone . intercalate ", " . sort . map show .: (++) `on` keys where orNone [] = "<none>" orNone e = e f .: g = (f .) . g infixr 8 .:
- tel 14y agoNice! I had (.) originally but reorganized it to compare better with the Clojure code. I really like (.:) and on though (which I'm always forgetting about).
- enigmo 14y agoThat's missing a `nub` or something to get the unique keys. You can also combine the maps first and the results will come out sorted and unique already.... since we're golfing: go :: (Show k, Ord k) => Map k v -> Map k v -> String go m1 m2 = orNone . intercalate ", " . fmap show . keys $ m1 <> m2 where orNone "" = "<none>" orNone x = x
- tel 14y agoBam! I didn't even think of taking advantage of the monoid.