mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
server: add hlint hints to replace case analysis with combinators (#6145)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
parent
39843e48f2
commit
0b98e8c504
@ -101,6 +101,14 @@
|
||||
- warn: {lhs: "onNothing x (pure y)", rhs: "pure (fromMaybe y x)"}
|
||||
- warn: {lhs: "onLeft x (return . f)", rhs: "return (either f id x)"}
|
||||
- warn: {lhs: "onLeft x (pure . f)", rhs: "pure (either f id x)"}
|
||||
- warn: {lhs: "case x of {Right a -> pure a; Left c -> d}", rhs: "onLeft x (\\ c -> d)"}
|
||||
- warn: {lhs: "case x of {Left c -> d; Right a -> pure a}", rhs: "onLeft x (\\ c -> d)"}
|
||||
- warn: {lhs: "case x of {Right a -> return a; Left c -> d}", rhs: "onLeft x (\\ c -> d)"}
|
||||
- warn: {lhs: "case x of {Left c -> d; Right a -> return a}", rhs: "onLeft x (\\ c -> d)"}
|
||||
- warn: {lhs: "case x of {Nothing -> a; Just b -> pure b}", rhs: "onNothing x a"}
|
||||
- warn: {lhs: "case x of {Just b -> pure b; Nothing -> a}", rhs: "onNothing x a"}
|
||||
- warn: {lhs: "case x of {Nothing -> a; Just b -> return b}", rhs: "onNothing x a"}
|
||||
- warn: {lhs: "case x of {Just b -> return b; Nothing -> a}", rhs: "onNothing x a"}
|
||||
|
||||
- group:
|
||||
name: data-text-extended
|
||||
|
@ -17,7 +17,6 @@ module Hasura.Prelude
|
||||
, liftEitherM
|
||||
-- * Efficient coercions
|
||||
, coerce
|
||||
, coerceSet
|
||||
, findWithIndex
|
||||
, mapFromL
|
||||
, oMapFromL
|
||||
@ -81,13 +80,11 @@ import qualified Data.ByteString.Lazy as BL
|
||||
import Data.Coerce
|
||||
import qualified Data.HashMap.Strict as Map
|
||||
import qualified Data.HashMap.Strict.InsOrd as OMap
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Encoding as TE
|
||||
import qualified Data.Text.Encoding.Error as TE
|
||||
import qualified GHC.Clock as Clock
|
||||
import qualified Test.QuickCheck as QC
|
||||
import Unsafe.Coerce
|
||||
|
||||
alphabet :: String
|
||||
alphabet = ['a'..'z'] ++ ['A'..'Z']
|
||||
@ -142,16 +139,6 @@ spanMaybeM f = go . toList
|
||||
Just y -> first (y:) <$> go xs
|
||||
Nothing -> pure ([], l)
|
||||
|
||||
-- | Efficiently coerce a set from one type to another.
|
||||
--
|
||||
-- This has the same safety properties as 'Set.mapMonotonic', and is equivalent
|
||||
-- to @Set.mapMonotonic coerce@ but is more efficient. This is safe to use when
|
||||
-- both @a@ and @b@ have automatically derived @Ord@ instances.
|
||||
--
|
||||
-- https://stackoverflow.com/q/57963881/176841
|
||||
coerceSet :: Coercible a b=> Set.Set a -> Set.Set b
|
||||
coerceSet = unsafeCoerce
|
||||
|
||||
findWithIndex :: (a -> Bool) -> [a] -> Maybe (a, Int)
|
||||
findWithIndex p l = do
|
||||
v <- find p l
|
||||
|
Loading…
Reference in New Issue
Block a user