graphql-engine/server/src-lib/Data/HashMap/Strict/InsOrd/Extended.hs
Robert 11a454c2d6 server, pro: actually reformat the code-base using ormolu
This commit applies ormolu to the whole Haskell code base by running `make format`.

For in-flight branches, simply merging changes from `main` will result in merge conflicts.
To avoid this, update your branch using the following instructions. Replace `<format-commit>`
by the hash of *this* commit.

$ git checkout my-feature-branch
$ git merge <format-commit>^    # and resolve conflicts normally
$ make format
$ git commit -a -m "reformat with ormolu"
$ git merge -s ours post-ormolu

https://github.com/hasura/graphql-engine-mono/pull/2404

GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
2021-09-23 22:57:37 +00:00

42 lines
1.0 KiB
Haskell

module Data.HashMap.Strict.InsOrd.Extended
( module OMap,
groupTuples,
groupListWith,
partition,
)
where
import Data.HashMap.Strict.InsOrd as OMap
import Data.Hashable (Hashable)
import Data.List qualified as L
import Data.Sequence.NonEmpty qualified as NE
import Prelude
groupTuples ::
(Eq k, Hashable k, Foldable t) =>
t (k, v) ->
OMap.InsOrdHashMap k (NE.NESeq v)
groupTuples =
L.foldl' groupFlds OMap.empty
where
groupFlds m (k, v) =
OMap.insertWith (flip (<>)) k (NE.singleton v) m
groupListWith ::
(Eq k, Hashable k, Foldable t, Functor t) =>
(v -> k) ->
t v ->
OMap.InsOrdHashMap k (NE.NESeq v)
groupListWith f l =
groupTuples $ fmap (\v -> (f v, v)) l
partition :: (Eq k, Hashable k) => (v -> Bool) -> OMap.InsOrdHashMap k v -> (OMap.InsOrdHashMap k v, OMap.InsOrdHashMap k v)
partition predicate =
OMap.foldlWithKey'
( \(left, right) key val ->
if (predicate val)
then (OMap.insert key val left, right)
else (left, OMap.insert key val right)
)
(mempty, mempty)