From 9b35cefdcb46b64f275da32709f093ace88fcfd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexandre=20Delano=C3=AB?= <devel+git@delanoe.org>
Date: Thu, 10 Dec 2020 08:08:47 +0100
Subject: [PATCH] [REFACT] more generic history of patch

---
 .../Core/Text/List/Social/History.hs          | 21 ++++++++++---------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/Gargantext/Core/Text/List/Social/History.hs b/src/Gargantext/Core/Text/List/Social/History.hs
index 469e85ba..3362139a 100644
--- a/src/Gargantext/Core/Text/List/Social/History.hs
+++ b/src/Gargantext/Core/Text/List/Social/History.hs
@@ -24,20 +24,20 @@ import Gargantext.Database.Schema.Ngrams (NgramsType(..))
 
 
 
-history :: Foldable t
-        => NgramsType
-        -> t ListId
+history :: (Foldable t, Foldable h)
+        => t NgramsType
+        -> h ListId
         -> Repo s NgramsStatePatch
-        -> Map ListId [Map NgramsTerm NgramsPatch]
-history nt lists = Map.unionsWith (<>)
-                 . map (Map.map cons)
-                 . map (Map.filterWithKey (\k _ -> List.elem k lists))
-                 . catMaybes
-                 . map (Map.lookup nt)
+        -> Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch])
+history types lists = Map.unionsWith (<>)
+                 . map (Map.map (Map.map cons))
+                 . map (Map.map ((Map.filterWithKey (\k _ -> List.elem k lists))))
+                 . map (Map.filterWithKey (\k _ -> List.elem k types))
                  . map toMap
                  . view r_history
   where
-    cons a = a : []
+    cons a = [a]
+
 
 toMap :: PatchMap NgramsType
            (PatchMap NodeId
@@ -57,3 +57,4 @@ toMap = Map.map (Map.map unNgramsTablePatch) . (Map.map toMap') . toMap'
     unNgramsTablePatch :: NgramsTablePatch -> Map NgramsTerm NgramsPatch
     unNgramsTablePatch (NgramsTablePatch p) = toMap' p
 
+
-- 
2.21.0