From 63f928b229308672ca74e3981b06b53460d0befb Mon Sep 17 00:00:00 2001 From: Ivan Jager Date: Thu, 27 Jun 2019 15:48:36 -0500 Subject: [PATCH] Fix import deduplication --- src/Ccap/Codegen/Purescript.purs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Ccap/Codegen/Purescript.purs b/src/Ccap/Codegen/Purescript.purs index 092efb5..378676a 100644 --- a/src/Ccap/Codegen/Purescript.purs +++ b/src/Ccap/Codegen/Purescript.purs @@ -13,10 +13,9 @@ import Control.Monad.Writer (class MonadTell, Writer, runWriter, tell) import Data.Array ((:)) import Data.Array as Array import Data.Array.NonEmpty as NonEmptyArray -import Data.Filterable (compact) -import Data.Foldable (any, intercalate) +import Data.Foldable (intercalate) import Data.Function (on) -import Data.Maybe (Maybe(..), fromMaybe, isNothing, maybe) +import Data.Maybe (Maybe(..), fromMaybe, maybe) import Data.String (Pattern(..)) import Data.String as String import Data.Traversable (for, for_, traverse) @@ -57,16 +56,12 @@ mergeImports :: Array PsImport -> Array PsImport mergeImports imps = let sorted = Array.sortBy ((compare `on` _.mod) <> (compare `on` _.alias)) imps - grouped = Array.groupBy (\a b -> a.mod == b.mod && b.alias == b.alias) sorted - in grouped <#> \group -> do - let typs = map _.typ group - { mod: (NonEmptyArray.head group).mod - , alias: (NonEmptyArray.head group).alias - , typ: - if any isNothing typs - then Nothing - else Just $ intercalate ", " (Array.nub <<< compact <<< NonEmptyArray.toArray $ typs) - } + grouped = Array.groupBy (\a b -> a.mod == b.mod && a.alias == b.alias) sorted + in grouped <#> \group -> + (NonEmptyArray.head group) + { typ = traverse _.typ group <#> NonEmptyArray.toArray + >>> Array.sort >>> Array.nub >>> intercalate ", " + } outputSpec :: String -> Array Module -> OutputSpec outputSpec defaultModulePrefix modules =