1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00
semantic/src/Prologue.hs

74 lines
2.5 KiB
Haskell
Raw Normal View History

2018-02-28 19:27:25 +03:00
{-# LANGUAGE UndecidableInstances #-}
module Prologue
( module X
, foldMapA
, maybeM
2018-04-16 22:48:45 +03:00
, maybeLast
, fromMaybeLast
) where
2018-02-27 18:37:09 +03:00
2018-02-28 19:33:24 +03:00
import Data.Bifunctor.Join as X
import Data.Bits as X
2018-02-28 19:33:24 +03:00
import Data.ByteString as X (ByteString)
2018-03-22 20:01:25 +03:00
import Data.Functor.Both as X (Both, both, runBothWith)
2018-02-28 19:33:24 +03:00
import Data.IntMap as X (IntMap)
import Data.IntSet as X (IntSet)
2018-03-22 20:01:25 +03:00
import Data.Ix as X (Ix (..))
import Data.List.NonEmpty as X (NonEmpty (..), nonEmpty, some1)
2018-02-28 19:33:24 +03:00
import Data.Map as X (Map)
import Data.Maybe as X
2018-03-22 20:01:25 +03:00
import Data.Monoid (Alt (..))
2018-02-28 19:33:24 +03:00
import Data.Sequence as X (Seq)
2018-06-15 18:41:15 +03:00
import Data.Semilattice.Lower as X (Lower(..))
2018-02-28 19:33:24 +03:00
import Data.Set as X (Set)
2018-05-17 01:25:02 +03:00
import Data.Sum as X (Sum, Element, Elements, (:<), (:<:), Apply (..), inject)
2018-02-28 19:33:24 +03:00
import Data.Text as X (Text)
import Data.These as X
import Data.Union as X
2018-03-22 20:01:25 +03:00
import Control.Exception as X hiding (Handler (..), assert, evaluate, throw, throwIO, throwTo)
2018-02-28 19:33:24 +03:00
-- Typeclasses
import Control.Applicative as X
import Control.Arrow as X ((&&&), (***))
2018-09-12 01:54:37 +03:00
import Control.Monad as X hiding (fail, return)
2018-03-22 20:01:25 +03:00
import Control.Monad.Except as X (MonadError (..))
import Control.Monad.Fail as X (MonadFail (..))
2018-02-28 19:33:24 +03:00
import Data.Algebra as X
import Data.Bifoldable as X
2018-03-22 20:01:25 +03:00
import Data.Bifunctor as X (Bifunctor (..))
2018-02-28 19:33:24 +03:00
import Data.Bitraversable as X
2018-03-22 20:01:25 +03:00
import Data.Foldable as X hiding (product, sum)
2018-02-28 19:33:24 +03:00
import Data.Function as X (fix, on, (&))
2018-03-22 20:01:25 +03:00
import Data.Functor as X (void, ($>))
2018-02-28 19:33:24 +03:00
import Data.Functor.Classes as X
import Data.Functor.Classes.Generic as X
2018-03-22 20:01:25 +03:00
import Data.Functor.Foldable as X (Base, Corecursive (..), Recursive (..))
import Data.Hashable as X (Hashable, hash, hashUsing, hashWithSalt)
2018-05-16 21:43:58 +03:00
import Data.Hashable.Lifted as X (Hashable1(..), hashWithSalt1)
2018-03-22 20:01:25 +03:00
import Data.Monoid as X (First (..), Last (..), Monoid (..))
import Data.Proxy as X (Proxy (..))
import Data.Semigroup as X (Semigroup (..))
2018-02-28 19:33:24 +03:00
import Data.Traversable as X
import Data.Typeable as X (Typeable)
-- Generics
import GHC.Generics as X hiding (moduleName)
2018-02-28 19:33:24 +03:00
import GHC.Stack as X
2018-03-15 23:14:51 +03:00
-- | Fold a collection by mapping each element onto an 'Alternative' action.
foldMapA :: (Alternative m, Foldable t) => (b -> m a) -> t b -> m a
foldMapA f = getAlt . foldMap (Alt . f)
2018-04-16 22:48:45 +03:00
maybeLast :: Foldable t => b -> (a -> b) -> t a -> b
maybeLast b f = maybe b f . getLast . foldMap (Last . Just)
fromMaybeLast :: Foldable t => a -> t a -> a
fromMaybeLast b = fromMaybe b . getLast . foldMap (Last . Just)
-- | Extract the 'Just' of a 'Maybe' in an 'Applicative' context or, given 'Nothing', run the provided action.
maybeM :: Applicative f => f a -> Maybe a -> f a
maybeM f = maybe f pure