]> Git — Sourcephile - gargantext.git/blob - notes/foldFinal.hs
[FIX] getNodesWithParentId == children with null parent_id
[gargantext.git] / notes / foldFinal.hs
1 {-# LANGUAGE ExistentialQuantification #-}
2 {-# LANGUAGE RankNTypes #-}
3
4 import Control.Lens (Getting, foldMapOf)
5
6 data Fold i o = forall m . Monoid m => Fold (i -> m) (m -> o)
7
8
9 instance Functor (Fold i) where
10 fmap k (Fold tally summarize) = Fold tally (k . summarize)
11
12 instance Applicative (Fold i) where
13 pure o = Fold (\_ -> ()) (\_ -> o)
14
15 Fold tallyF summarizeF <*> Fold tallyX summarizeX = Fold tally summarize
16 where
17 tally i = (tallyF i, tallyX i)
18 summarize (nF, nX) = summarizeF nF (summarizeX nX)
19
20 focus :: (forall m . Monoid m => Getting m b a) -> Fold a o -> Fold b o
21 focus lens (Fold tally summarize) = Fold (foldMapOf lens tally) summarize
22
23
24
25