2 Module : Gargantext.Core.Text.List.Group
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE TemplateHaskell #-}
13 {-# LANGUAGE ConstraintKinds #-}
14 {-# LANGUAGE TypeFamilies #-}
15 {-# LANGUAGE FunctionalDependencies #-}
16 {-# LANGUAGE InstanceSigs #-}
18 module Gargantext.Core.Text.List.Group
21 import Control.Lens (view)
23 import Data.Maybe (fromMaybe)
24 import Data.Monoid (Monoid, mempty)
25 import Data.Text (Text)
26 import Gargantext.Core.Text.List.Social.Prelude
27 import Gargantext.Core.Text.List.Group.Prelude
28 import Gargantext.Core.Text.List.Group.WithScores
29 import Gargantext.Prelude
30 import qualified Data.Map as Map
32 ------------------------------------------------------------------------
33 toGroupedTree :: (Ord a, Monoid a)
34 => FlowCont Text FlowListScores
36 -> FlowCont Text (GroupedTreeScores a)
37 toGroupedTree flc scores =
38 groupWithScores' flc scoring
40 scoring t = fromMaybe mempty $ Map.lookup t scores
43 ------------------------------------------------------------------------
44 setScoresWithMap :: (Ord a, Ord b, Monoid b) => Map Text b
45 -> Map Text (GroupedTreeScores a)
46 -> Map Text (GroupedTreeScores b)
47 setScoresWithMap m = setScoresWith (score m)
49 score m' t = case Map.lookup t m' of
53 setScoresWith :: (Ord a, Ord b)
55 -> Map Text (GroupedTreeScores a)
56 -> Map Text (GroupedTreeScores b)
58 -- | This Type level lenses solution does not work
59 setScoresWith f = Map.mapWithKey (\k v -> over gts'_children (setScoresWith f)
60 $ set gts'_score (f k) v
63 setScoresWith f = Map.mapWithKey (\k v -> v { _gts'_score = f k
64 , _gts'_children = setScoresWith f
65 $ view gts'_children v
68 ------------------------------------------------------------------------