Commit 39aa6434 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Prelude] listToCombi(naisons), thanks to Quentin, authors of this nice function.

parent f37b439f
...@@ -147,9 +147,7 @@ getCoocByNgramsOnly cId nt ngs = do ...@@ -147,9 +147,7 @@ getCoocByNgramsOnly cId nt ngs = do
<$> Map.lookup t1 ngs' <$> Map.lookup t1 ngs'
<*> Map.lookup t2 ngs' <*> Map.lookup t2 ngs'
) )
| (t1,t2) <- list2combi $ Map.keys ngs'] | (t1,t2) <- listToCombi identity $ Map.keys ngs']
where
list2combi = undefined
getNodesByNgramsOnlyUser :: CorpusId -> NgramsType -> [Text] -> Cmd err (Map Text (Set NodeId)) getNodesByNgramsOnlyUser :: CorpusId -> NgramsType -> [Text] -> Cmd err (Map Text (Set NodeId))
getNodesByNgramsOnlyUser cId nt ngs = fromListWith (<>) <$> map (\(n,t) -> (t, Set.singleton n)) getNodesByNgramsOnlyUser cId nt ngs = fromListWith (<>) <$> map (\(n,t) -> (t, Set.singleton n))
......
...@@ -258,3 +258,8 @@ zipSnd f xs = zip xs (f xs) ...@@ -258,3 +258,8 @@ zipSnd f xs = zip xs (f xs)
maximumWith :: (Ord a1, Foldable t) => (a2 -> a1) -> t a2 -> a2 maximumWith :: (Ord a1, Foldable t) => (a2 -> a1) -> t a2 -> a2
maximumWith f = L.maximumBy (compare `on` f) maximumWith f = L.maximumBy (compare `on` f)
-- | To get all combinations of a list with no repetition and apply a function to the resulting list of pairs
listToCombi :: forall a b. (a -> b) -> [a] -> [(b,b)]
listToCombi f l = [ (f x, f y) | (x:rest) <- L.tails l, y <- rest ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment