graphql-engine/server/src-lib/Data/List/Extended.hs
Karthikeyan Chinnakonda 39a4352569 Merge pull request #113 from hasura/karthikeyan/remote-schema-permissions
server: remote schema permissions
GitOrigin-RevId: 63b9717e30351676c9474bdfddd3ad1ee1409eea
2020-12-21 09:12:35 +00:00

26 lines
745 B
Haskell

module Data.List.Extended
( duplicates
, uniques
, getDifference
, module L
) where
import Data.Hashable (Hashable)
import Data.Function (on)
import Prelude
import qualified Data.HashMap.Strict as Map
import qualified Data.HashSet as Set
import qualified Data.List as L
import qualified Data.List.NonEmpty as NE
duplicates :: (Eq a, Hashable a) => [a] -> Set.HashSet a
duplicates =
Set.fromList . Map.keys . Map.filter (> 1) . Map.fromListWith (+) . map (,1::Int)
uniques :: Eq a => [a] -> [a]
uniques = map NE.head . NE.group
getDifference :: (Eq a, Hashable a) => [a] -> [a] -> Set.HashSet a
getDifference = Set.difference `on` Set.fromList