module Chez.Grater.Internal.Prelude
  ( module Prelude
  , module Control.Applicative
  , module Control.Arrow
  , module Control.Exception
  , module Control.Monad
  , module Data.CaseInsensitive
  , module Data.HashMap.Strict
  , module Data.List
  , module Data.Map.Strict
  , module Data.Maybe
  , module Data.Set
  , module Data.Text
  , module Data.Traversable
  , nubOrd, uncurry3, uncurry4, tshow, headMay, lastMay
  ) where

import Control.Applicative ((<|>), optional)
import Control.Arrow (first, left, right, second)
import Control.Exception (Exception, throwIO)
import Control.Monad (replicateM, void)
import Data.CaseInsensitive (CI)
import Data.Containers.ListUtils (nubOrd)
import Data.HashMap.Strict (HashMap)
import Data.List (find, groupBy, sortBy, sortOn)
import Data.Map.Strict (Map)
import Data.Maybe (catMaybes, fromMaybe, mapMaybe)
import Data.Set (Set)
import Data.Text (Text)
import Data.Traversable (for)
import Prelude
import qualified Data.Text as Text

uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 a -> b -> c -> d
f (a
x, b
y, c
z) = a -> b -> c -> d
f a
x b
y c
z

uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
uncurry4 a -> b -> c -> d -> e
f (a
x, b
y, c
z, d
w) = a -> b -> c -> d -> e
f a
x b
y c
z d
w

tshow :: Show a => a -> Text
tshow :: a -> Text
tshow = String -> Text
Text.pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show

headMay :: [a] -> Maybe a
headMay :: [a] -> Maybe a
headMay = \case
  a
x:[a]
_ -> a -> Maybe a
forall a. a -> Maybe a
Just a
x
  [] -> Maybe a
forall a. Maybe a
Nothing

lastMay :: [a] -> Maybe a
lastMay :: [a] -> Maybe a
lastMay = [a] -> Maybe a
forall a. [a] -> Maybe a
headMay ([a] -> Maybe a) -> ([a] -> [a]) -> [a] -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse