{-#LANGUAGE DerivingStrategies #-}
{-#LANGUAGE FlexibleContexts #-}
{-#LANGUAGE FlexibleInstances #-}
{-#LANGUAGE GeneralizedNewtypeDeriving #-}
{-#LANGUAGE OverloadedStrings #-}
{-#LANGUAGE TupleSections #-}
{-#LANGUAGE TypeSynonymInstances #-}
{-#LANGUAGE MultiParamTypeClasses #-}
{-#LANGUAGE ScopedTypeVariables #-}
{-#LANGUAGE LambdaCase #-}

-- | Implementations of the default template context functions and values. You
-- will not normally need to import this module, unless you want to provide
-- your own context with things that reuse functionality from the default
-- ones.
module Text.Ginger.Run.Builtins
where

import Prelude ( (.), ($), (==), (/=)
               , (>), (<), (>=), (<=)
               , (+), (-), (*), (/), div, (**), (^)
               , (||), (&&)
               , (++)
               , Show, show
               , undefined, otherwise
               , Maybe (..)
               , Bool (..)
               , Int, Integer, String
               , fromIntegral, floor, round
               , not
               , show
               , uncurry
               , seq
               , fst, snd
               , maybe
               , Either (..)
               , id
               , flip
               , const
               , either
               )
import qualified Prelude
import Data.Maybe (fromMaybe, isJust, isNothing)
import qualified Data.List as List
import Text.Ginger.AST
import Text.Ginger.Html
import Text.Ginger.GVal
import Text.Ginger.Run.Type
import Text.Ginger.Run.FuncUtils
import Text.Ginger.Run.VM
import Text.Printf
import Text.PrintfA

import Data.Text (Text)
import Data.String (fromString)
import qualified Data.Text as Text
import qualified Data.ByteString.UTF8 as UTF8
import qualified Data.ByteString.Lazy as LBS
import Control.Monad
import Control.Monad.Writer
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Except (throwError, MonadError)
import Control.Applicative
import qualified Data.HashMap.Strict as HashMap
import Data.HashMap.Strict (HashMap)
import Data.Scientific (Scientific, formatScientific, FPFormat (Fixed) )
import qualified Data.Scientific as Scientific
import Data.Default (def)
import Safe (readMay, lastDef, headMay)
import Network.HTTP.Types (urlEncode)
import Debug.Trace (trace)
import Data.List (lookup, zipWith, unzip, foldl')
import Data.Monoid (Monoid (..), (<>))
import Data.Time ( defaultTimeLocale
                 , formatTime
                 , LocalTime (..)
                 , ZonedTime (..)
                 , utc
                 , utcToZonedTime
                 , zonedTimeToUTC
                 , TimeOfDay (..)
                 , fromGregorian
                 , Day (..)
                 , parseTimeM
                 , TimeLocale (..)
                 , TimeZone (..)
                 )
import Data.Foldable (asum, toList)
import qualified Data.Aeson as JSON
import qualified Data.Aeson.Encode.Pretty as JSON
import qualified Text.Regex.TDFA as RE

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

gfnRawHtml :: Monad m => Function (Run p m h)
gfnRawHtml :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnRawHtml = (GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
forall (m :: * -> *) h p.
Monad m =>
(GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
unaryFunc (Html -> GVal (Run p m h)
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Html -> GVal (Run p m h))
-> (GVal (Run p m h) -> Html)
-> GVal (Run p m h)
-> GVal (Run p m h)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Html
unsafeRawHtml (Text -> Html)
-> (GVal (Run p m h) -> Text) -> GVal (Run p m h) -> Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal (Run p m h) -> Text
forall (m :: * -> *). GVal m -> Text
asText)

gfnUrlEncode :: Monad m => Function (Run p m h)
gfnUrlEncode :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnUrlEncode =
    (GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
forall (m :: * -> *) h p.
Monad m =>
(GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
unaryFunc
        ( Text -> GVal (Run p m h)
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal
        (Text -> GVal (Run p m h))
-> (GVal (Run p m h) -> Text)
-> GVal (Run p m h)
-> GVal (Run p m h)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
Text.pack
        ([Char] -> Text)
-> (GVal (Run p m h) -> [Char]) -> GVal (Run p m h) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [Char]
UTF8.toString
        (ByteString -> [Char])
-> (GVal (Run p m h) -> ByteString) -> GVal (Run p m h) -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> ByteString -> ByteString
urlEncode Bool
True
        (ByteString -> ByteString)
-> (GVal (Run p m h) -> ByteString)
-> GVal (Run p m h)
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
UTF8.fromString
        ([Char] -> ByteString)
-> (GVal (Run p m h) -> [Char]) -> GVal (Run p m h) -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
Text.unpack
        (Text -> [Char])
-> (GVal (Run p m h) -> Text) -> GVal (Run p m h) -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal (Run p m h) -> Text
forall (m :: * -> *). GVal m -> Text
asText
        )

gfnDefault :: Monad m => Function m
gfnDefault :: forall (m :: * -> *). Monad m => Function m
gfnDefault [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
forall a. Default a => a
def
gfnDefault ((Maybe Text
_, GVal m
x):[(Maybe Text, GVal m)]
xs)
    | GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal m
x = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
x
    | Bool
otherwise = Function m
forall (m :: * -> *). Monad m => Function m
gfnDefault [(Maybe Text, GVal m)]
xs

gfnEscape :: Monad m => Function m
gfnEscape :: forall (m :: * -> *). Monad m => Function m
gfnEscape = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m))
-> ([(Maybe Text, GVal m)] -> GVal m)
-> [(Maybe Text, GVal m)]
-> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Html -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Html -> GVal m)
-> ([(Maybe Text, GVal m)] -> Html)
-> [(Maybe Text, GVal m)]
-> GVal m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Html
html (Text -> Html)
-> ([(Maybe Text, GVal m)] -> Text)
-> [(Maybe Text, GVal m)]
-> Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ([(Maybe Text, GVal m)] -> [Text])
-> [(Maybe Text, GVal m)]
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Maybe Text, GVal m) -> Text) -> [(Maybe Text, GVal m)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal m -> Text)
-> ((Maybe Text, GVal m) -> GVal m) -> (Maybe Text, GVal m) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd)

-- Check if all arguments are HTML-\"escaped\" (sic!) NOTE that this doesn't
-- really make much sense considering the way Ginger works - every GVal is, by
-- construction, both escaped in its 'asGVal' representation and not escaped in
-- its 'asText' representation, at the same time.
-- So what we check instead is whether the current 'asHtml'representation of
-- the value is exactly the same as what explicitly HTML-encoding the 'asText'
-- representation would give. In other words, we check whether the HTML
-- representations of @{{ v }}@ and @{{ v|escape }}@ match.
gfnEscaped :: Monad m => Function m
gfnEscaped :: forall (m :: * -> *). Monad m => Function m
gfnEscaped = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m))
-> ([(Maybe Text, GVal m)] -> GVal m)
-> [(Maybe Text, GVal m)]
-> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> GVal m)
-> ([(Maybe Text, GVal m)] -> Bool)
-> [(Maybe Text, GVal m)]
-> GVal m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Maybe Text, GVal m) -> Bool) -> [(Maybe Text, GVal m)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.all (GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
isEscaped (GVal m -> Bool)
-> ((Maybe Text, GVal m) -> GVal m) -> (Maybe Text, GVal m) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd)
  where
    isEscaped :: GVal m -> Bool
isEscaped GVal m
v =
      (GVal Any -> Html
forall (m :: * -> *). GVal m -> Html
asHtml (GVal Any -> Html) -> (GVal m -> GVal Any) -> GVal m -> Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Html -> GVal Any
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Html -> GVal Any) -> (GVal m -> Html) -> GVal m -> GVal Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Html
html (Text -> Html) -> (GVal m -> Text) -> GVal m -> Html
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal m -> Html) -> GVal m -> Html
forall a b. (a -> b) -> a -> b
$ GVal m
v) Html -> Html -> Bool
forall a. Eq a => a -> a -> Bool
==
      (GVal m -> Html
forall (m :: * -> *). GVal m -> Html
asHtml GVal m
v)

gfnAny :: Monad m => Function m
gfnAny :: forall (m :: * -> *). Monad m => Function m
gfnAny [(Maybe Text, GVal m)]
xs = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ ((Maybe Text, GVal m) -> Bool) -> [(Maybe Text, GVal m)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.any (GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean (GVal m -> Bool)
-> ((Maybe Text, GVal m) -> GVal m) -> (Maybe Text, GVal m) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd) [(Maybe Text, GVal m)]
xs

gfnAll :: Monad m => Function m
gfnAll :: forall (m :: * -> *). Monad m => Function m
gfnAll [(Maybe Text, GVal m)]
xs = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ ((Maybe Text, GVal m) -> Bool) -> [(Maybe Text, GVal m)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean (GVal m -> Bool)
-> ((Maybe Text, GVal m) -> GVal m) -> (Maybe Text, GVal m) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd) [(Maybe Text, GVal m)]
xs

gfnIn :: Monad m => Function m
gfnIn :: forall (m :: * -> *). Monad m => Function m
gfnIn [] =
  GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
forall a. Default a => a
def
gfnIn [(Maybe Text, GVal m)
needle] =
  GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
False
gfnIn [(Maybe Text
_, GVal m
needle),(Maybe Text
_, GVal m
haystack)] =
  GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ GVal m -> GVal m -> Bool
forall (m :: * -> *). GVal m -> GVal m -> Bool
inDict GVal m
needle GVal m
haystack Bool -> Bool -> Bool
|| GVal m -> GVal m -> Bool
forall (m :: * -> *). GVal m -> GVal m -> Bool
inList GVal m
needle GVal m
haystack

inList :: GVal m -> GVal m -> Bool
inList :: forall (m :: * -> *). GVal m -> GVal m -> Bool
inList GVal m
needle GVal m
haystack =
  Bool -> ([GVal m] -> Bool) -> Maybe [GVal m] -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    Bool
False
    ((GVal m -> Bool) -> [GVal m] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.any (GVal m -> GVal m -> Bool
forall (m :: * -> *). GVal m -> GVal m -> Bool
looseEquals GVal m
needle))
    (GVal m -> Maybe [GVal m]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal m
haystack)

inDict :: GVal m -> GVal m -> Bool
inDict :: forall (m :: * -> *). GVal m -> GVal m -> Bool
inDict GVal m
needle GVal m
haystack =
  Maybe (GVal m) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (GVal m) -> Bool) -> Maybe (GVal m) -> Bool
forall a b. (a -> b) -> a -> b
$ Text -> GVal m -> Maybe (GVal m)
forall (m :: * -> *). Text -> GVal m -> Maybe (GVal m)
lookupKey (GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText GVal m
needle) GVal m
haystack

gfnApply :: Monad m => Function (Run p m h)
gfnApply :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnApply [] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def
gfnApply [(Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
_] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def
gfnApply ((Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fg):(Maybe Text
_,GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
a):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
xs) =
  case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fg of
    Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
Nothing -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"apply") Text
"Tried to call something that isn't a function"
    Just Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f ->
      let args :: [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args = ((GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> (Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text
forall a. Maybe a
Nothing,) ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [(Maybe Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))])
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> [GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe
   [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Maybe
         [GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> [(Maybe Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))])
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
a) [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a. [a] -> [a] -> [a]
++ [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
xs
      in Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args

gfnEquals :: Monad m => Function m
gfnEquals :: forall (m :: * -> *). Monad m => Function m
gfnEquals [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
True
gfnEquals [(Maybe Text, GVal m)
x] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
True
gfnEquals ((Maybe Text, GVal m)
x:[(Maybe Text, GVal m)]
xs) =
    GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ ((Maybe Text, GVal m) -> Bool) -> [(Maybe Text, GVal m)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (((Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd (Maybe Text, GVal m)
x GVal m -> GVal m -> Bool
forall (m :: * -> *). GVal m -> GVal m -> Bool
`looseEquals`) (GVal m -> Bool)
-> ((Maybe Text, GVal m) -> GVal m) -> (Maybe Text, GVal m) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd) [(Maybe Text, GVal m)]
xs

gfnNEquals :: Monad m => Function m
gfnNEquals :: forall (m :: * -> *). Monad m => Function m
gfnNEquals [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
True
gfnNEquals [(Maybe Text, GVal m)
x] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
True
gfnNEquals ((Maybe Text, GVal m)
x:[(Maybe Text, GVal m)]
xs) =
    GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ ((Maybe Text, GVal m) -> Bool) -> [(Maybe Text, GVal m)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.any (Bool -> Bool
not (Bool -> Bool)
-> ((Maybe Text, GVal m) -> Bool) -> (Maybe Text, GVal m) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd (Maybe Text, GVal m)
x GVal m -> GVal m -> Bool
forall (m :: * -> *). GVal m -> GVal m -> Bool
`looseEquals`) (GVal m -> Bool)
-> ((Maybe Text, GVal m) -> GVal m) -> (Maybe Text, GVal m) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd) [(Maybe Text, GVal m)]
xs

gfnContains :: Monad m => Function (Run p m h)
gfnContains :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnContains [] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Bool
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
False
gfnContains ((Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
list:[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
elems) = do
    [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
rawList <- RuntimeError p
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *) p a h.
Monad m =>
RuntimeError p -> a -> Maybe a -> Run p m h a
warnFromMaybe ([Text] -> Maybe Text -> RuntimeError p
forall p. [Text] -> Maybe Text -> RuntimeError p
TypeError [Text
"list"] (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Text
forall a. Show a => a -> Text
tshow (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
list)) [] (Maybe
   [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> Run
      p
      m
      h
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> ((Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Maybe
         [GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Maybe
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> ((Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd ((Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Run
      p
      m
      h
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> a -> b
$ (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
list
    let rawElems :: [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
rawElems = ((Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
elems
        GVal m
e isInList :: GVal m -> t (GVal m) -> Bool
`isInList` t (GVal m)
xs = (GVal m -> Bool) -> t (GVal m) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.any (GVal m -> GVal m -> Bool
forall (m :: * -> *). GVal m -> GVal m -> Bool
looseEquals GVal m
e) t (GVal m)
xs
        t (GVal m)
es areInList :: t (GVal m) -> t (GVal m) -> Bool
`areInList` t (GVal m)
xs = (GVal m -> Bool) -> t (GVal m) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (GVal m -> t (GVal m) -> Bool
forall {t :: * -> *} {m :: * -> *}.
Foldable t =>
GVal m -> t (GVal m) -> Bool
`isInList` t (GVal m)
xs) t (GVal m)
es
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Bool
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Bool
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Bool
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
rawElems [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Bool
forall {t :: * -> *} {t :: * -> *} {m :: * -> *}.
(Foldable t, Foldable t) =>
t (GVal m) -> t (GVal m) -> Bool
`areInList` [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
rawList

gfnConcat :: Monad m => Function m
gfnConcat :: forall (m :: * -> *). Monad m => Function m
gfnConcat [] =
  GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
False
gfnConcat [(Maybe Text, GVal m)
x] =
  GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd (Maybe Text, GVal m)
x)
gfnConcat ((Maybe Text, GVal m)
x:[(Maybe Text, GVal m)]
xs) =
  GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ (GVal m -> GVal m -> GVal m) -> GVal m -> [GVal m] -> GVal m
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' GVal m -> GVal m -> GVal m
forall (m :: * -> *). GVal m -> GVal m -> GVal m
gappend ((Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd (Maybe Text, GVal m)
x) (((Maybe Text, GVal m) -> GVal m)
-> [(Maybe Text, GVal m)] -> [GVal m]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd [(Maybe Text, GVal m)]
xs)

looseEquals :: GVal m -> GVal m -> Bool
looseEquals :: forall (m :: * -> *). GVal m -> GVal m -> Bool
looseEquals GVal m
a GVal m
b
    | Maybe (Function m) -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe (Function m)
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal m
a) Bool -> Bool -> Bool
|| Maybe (Function m) -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe (Function m)
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal m
b) = Bool
False
    | Maybe [GVal m] -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe [GVal m]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal m
a) Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Maybe [GVal m] -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe [GVal m]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal m
b) = Bool
False
    | Maybe [(Text, GVal m)] -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe [(Text, GVal m)]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal m
a) Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Maybe [(Text, GVal m)] -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe [(Text, GVal m)]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal m
b) = Bool
False
    -- Both numbers: do numeric comparison
    | Maybe Scientific -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
a) Bool -> Bool -> Bool
&& Maybe Scientific -> Bool
forall a. Maybe a -> Bool
isJust (GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
b) = GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
a Maybe Scientific -> Maybe Scientific -> Bool
forall a. Eq a => a -> a -> Bool
== GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
b
    -- If either is NULL, the other must be falsy
    | GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
isNull GVal m
a Bool -> Bool -> Bool
|| GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
isNull GVal m
b = GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal m
a Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal m
b
    | Bool
otherwise = GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText GVal m
a Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText GVal m
b

gfnLess :: Monad m => Function m
gfnLess :: forall (m :: * -> *). Monad m => Function m
gfnLess [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool
False
gfnLess [(Maybe Text, GVal m)]
xs' =
    let xs :: [GVal m]
xs = ((Maybe Text, GVal m) -> GVal m)
-> [(Maybe Text, GVal m)] -> [GVal m]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd [(Maybe Text, GVal m)]
xs'
    in GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$
        (Maybe Bool -> Bool) -> [Maybe Bool] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True) ((GVal m -> GVal m -> Maybe Bool)
-> [GVal m] -> [GVal m] -> [Maybe Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
Prelude.zipWith GVal m -> GVal m -> Maybe Bool
forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
less [GVal m]
xs ([GVal m] -> [GVal m]
forall a. HasCallStack => [a] -> [a]
Prelude.tail [GVal m]
xs))

gfnGreater :: Monad m => Function m
gfnGreater :: forall (m :: * -> *). Monad m => Function m
gfnGreater [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool
False
gfnGreater [(Maybe Text, GVal m)]
xs' =
    let xs :: [GVal m]
xs = ((Maybe Text, GVal m) -> GVal m)
-> [(Maybe Text, GVal m)] -> [GVal m]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd [(Maybe Text, GVal m)]
xs'
    in GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$
        (Maybe Bool -> Bool) -> [Maybe Bool] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True) ((GVal m -> GVal m -> Maybe Bool)
-> [GVal m] -> [GVal m] -> [Maybe Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
Prelude.zipWith GVal m -> GVal m -> Maybe Bool
forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
greater [GVal m]
xs ([GVal m] -> [GVal m]
forall a. HasCallStack => [a] -> [a]
Prelude.tail [GVal m]
xs))

gfnLessEquals :: Monad m => Function m
gfnLessEquals :: forall (m :: * -> *). Monad m => Function m
gfnLessEquals [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool
False
gfnLessEquals [(Maybe Text, GVal m)]
xs' =
    let xs :: [GVal m]
xs = ((Maybe Text, GVal m) -> GVal m)
-> [(Maybe Text, GVal m)] -> [GVal m]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd [(Maybe Text, GVal m)]
xs'
    in GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$
        (Maybe Bool -> Bool) -> [Maybe Bool] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True) ((GVal m -> GVal m -> Maybe Bool)
-> [GVal m] -> [GVal m] -> [Maybe Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
Prelude.zipWith GVal m -> GVal m -> Maybe Bool
forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
lessEq [GVal m]
xs ([GVal m] -> [GVal m]
forall a. HasCallStack => [a] -> [a]
Prelude.tail [GVal m]
xs))

gfnGreaterEquals :: Monad m => Function m
gfnGreaterEquals :: forall (m :: * -> *). Monad m => Function m
gfnGreaterEquals [] = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Bool
False
gfnGreaterEquals [(Maybe Text, GVal m)]
xs' =
    let xs :: [GVal m]
xs = ((Maybe Text, GVal m) -> GVal m)
-> [(Maybe Text, GVal m)] -> [GVal m]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd [(Maybe Text, GVal m)]
xs'
    in GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Bool -> GVal m) -> Bool -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool -> m (GVal m)) -> Bool -> m (GVal m)
forall a b. (a -> b) -> a -> b
$
        (Maybe Bool -> Bool) -> [Maybe Bool] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Prelude.all (Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True) ((GVal m -> GVal m -> Maybe Bool)
-> [GVal m] -> [GVal m] -> [Maybe Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
Prelude.zipWith GVal m -> GVal m -> Maybe Bool
forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
greaterEq [GVal m]
xs ([GVal m] -> [GVal m]
forall a. HasCallStack => [a] -> [a]
Prelude.tail [GVal m]
xs))

less :: Monad m => GVal m -> GVal m -> Maybe Bool
less :: forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
less GVal m
a GVal m
b = Scientific -> Scientific -> Bool
forall a. Ord a => a -> a -> Bool
(<) (Scientific -> Scientific -> Bool)
-> Maybe Scientific -> Maybe (Scientific -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
a Maybe (Scientific -> Bool) -> Maybe Scientific -> Maybe Bool
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
b

greater :: Monad m => GVal m -> GVal m -> Maybe Bool
greater :: forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
greater GVal m
a GVal m
b = Scientific -> Scientific -> Bool
forall a. Ord a => a -> a -> Bool
(>) (Scientific -> Scientific -> Bool)
-> Maybe Scientific -> Maybe (Scientific -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
a Maybe (Scientific -> Bool) -> Maybe Scientific -> Maybe Bool
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
b

lessEq :: Monad m => GVal m -> GVal m -> Maybe Bool
lessEq :: forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
lessEq GVal m
a GVal m
b = Scientific -> Scientific -> Bool
forall a. Ord a => a -> a -> Bool
(<=) (Scientific -> Scientific -> Bool)
-> Maybe Scientific -> Maybe (Scientific -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
a Maybe (Scientific -> Bool) -> Maybe Scientific -> Maybe Bool
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
b

greaterEq :: Monad m => GVal m -> GVal m -> Maybe Bool
greaterEq :: forall (m :: * -> *). Monad m => GVal m -> GVal m -> Maybe Bool
greaterEq GVal m
a GVal m
b = Scientific -> Scientific -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (Scientific -> Scientific -> Bool)
-> Maybe Scientific -> Maybe (Scientific -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
a Maybe (Scientific -> Bool) -> Maybe Scientific -> Maybe Bool
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
b

difference :: Prelude.Num a => [a] -> a
difference :: forall a. Num a => [a] -> a
difference (a
x:[a]
xs) = a
x a -> a -> a
forall a. Num a => a -> a -> a
- [a] -> a
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
Prelude.sum [a]
xs
difference [] = a
0

ratio :: (Show a, Prelude.Fractional a, Prelude.Num a) => [a] -> a
ratio :: forall a. (Show a, Fractional a, Num a) => [a] -> a
ratio (a
x:[a]
xs) = a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ [a] -> a
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
Prelude.product [a]
xs
ratio [] = a
0

intRatio :: (Prelude.Integral a, Prelude.Num a) => [a] -> a
intRatio :: forall a. (Integral a, Num a) => [a] -> a
intRatio (a
x:[a]
xs) = a
x a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.div` [a] -> a
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
Prelude.product [a]
xs
intRatio [] = a
0

modulo :: (Prelude.Integral a, Prelude.Num a) => [a] -> a
modulo :: forall a. (Integral a, Num a) => [a] -> a
modulo (a
x:[a]
xs) = a
x a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.mod` [a] -> a
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
Prelude.product [a]
xs
modulo [] = a
0

capitalize :: Text -> Text
capitalize :: Text -> Text
capitalize Text
txt = Text -> Text
Text.toUpper (Int -> Text -> Text
Text.take Int
1 Text
txt) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
Text.drop Int
1 Text
txt

gfnCenter :: Monad m => Function m
gfnCenter :: forall (m :: * -> *). Monad m => Function m
gfnCenter [] = Function m
forall (m :: * -> *). Monad m => Function m
gfnCenter [(Maybe Text
forall a. Maybe a
Nothing, Text -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text
"" :: Text))]
gfnCenter [(Maybe Text, GVal m)
x] = Function m
forall (m :: * -> *). Monad m => Function m
gfnCenter [(Maybe Text, GVal m)
x, (Maybe Text
forall a. Maybe a
Nothing, Int -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
80 :: Int))]
gfnCenter [(Maybe Text, GVal m)
x,(Maybe Text, GVal m)
y] = Function m
forall (m :: * -> *). Monad m => Function m
gfnCenter [(Maybe Text, GVal m)
x, (Maybe Text, GVal m)
y, (Maybe Text
forall a. Maybe a
Nothing, Text -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text
" " :: Text))]
gfnCenter ((Maybe Text
_, GVal m
s):(Maybe Text
_, GVal m
w):(Maybe Text
_, GVal m
pad):[(Maybe Text, GVal m)]
_) =
    GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> (Text -> GVal m) -> Text -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text -> m (GVal m)) -> Text -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Text -> Text
center (GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText GVal m
s) (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
80 (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ Scientific -> Int
forall b. Integral b => Scientific -> b
forall a b. (RealFrac a, Integral b) => a -> b
Prelude.truncate (Scientific -> Int) -> Maybe Scientific -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
w) (GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText GVal m
pad)

gfnLength :: Monad m => Function (Run p m h)
gfnLength :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnLength [] =
  GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def
gfnLength ((Maybe Text
_,GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
x):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
_) =
  case (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [(Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
x, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
x) of
    (Maybe
  [(Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
Nothing, Maybe
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
Nothing) ->
      GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Int)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Int
Text.length (Text -> Int)
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Text)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
x
    (Just [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
items, Maybe
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_) ->
      GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ([(Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ([(Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
    -> Int)
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length ([(Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
items
    (Maybe
  [(Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
_, Just [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
items) ->
      GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ([GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ([GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
    -> Int)
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
items

gfnSlice :: Monad m => Function (Run p m h)
gfnSlice :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnSlice [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
    let argValues :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
argValues =
            [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
                [ (Text
"slicee", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"start", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"length", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                ]
                [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    in case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
argValues of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
slicee, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
startPos, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
length] -> do
            let startInt :: Int
                startInt :: Int
startInt = Int -> (Scientific -> Int) -> Maybe Scientific -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 Scientific -> Int
forall b. Integral b => Scientific -> b
forall a b. (RealFrac a, Integral b) => a -> b
Prelude.round (Maybe Scientific -> Int)
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Maybe Scientific)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Int)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Int
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
startPos

                lengthInt :: Maybe Int
                lengthInt :: Maybe Int
lengthInt = (Scientific -> Int) -> Maybe Scientific -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Scientific -> Int
forall b. Integral b => Scientific -> b
forall a b. (RealFrac a, Integral b) => a -> b
Prelude.round (Maybe Scientific -> Maybe Int)
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Maybe Scientific)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Maybe Int)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe Int
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
length

                slice :: [a] -> Int -> Maybe Int -> [a]
                slice :: forall a. [a] -> Int -> Maybe Int -> [a]
slice [a]
xs Int
start Maybe Int
Nothing
                    | Int
start Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 =
                        Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
Prelude.drop ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [a]
xs Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
start) [a]
xs
                    | Bool
otherwise =
                        Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
Prelude.drop Int
start [a]
xs
                slice [a]
xs Int
start (Just Int
length) =
                    Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
Prelude.take Int
length ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ [a] -> Int -> Maybe Int -> [a]
forall a. [a] -> Int -> Maybe Int -> [a]
slice [a]
xs Int
start Maybe Int
forall a. Maybe a
Nothing
            case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [(Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
slicee of
                Just [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
items -> do
                    let slicedItems :: [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
slicedItems = [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Int
-> Maybe Int
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a. [a] -> Int -> Maybe Int -> [a]
slice [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
items Int
startInt Maybe Int
lengthInt
                    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). [Pair m] -> GVal m
dict [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
slicedItems
                Maybe
  [(Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
Nothing ->
                    case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
slicee of
                    Just [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
items ->
                        GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ([GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Int
-> Maybe Int
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. [a] -> Int -> Maybe Int -> [a]
slice [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
items Int
startInt Maybe Int
lengthInt
                    Maybe
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
Nothing ->
                        GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ([Char]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [Char]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ([Char] -> Text)
-> [Char]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
Text.pack ([Char]
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [Char]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$
                            [Char] -> Int -> Maybe Int -> [Char]
forall a. [a] -> Int -> Maybe Int -> [a]
slice (Text -> [Char]
Text.unpack (Text -> [Char]) -> Text -> [Char]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
slicee) Int
startInt Maybe Int
lengthInt
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"slice") Text
"expected: (slicee, start=0, length=null)"

gfnReplace :: Monad m => Function (Run p m h)
gfnReplace :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnReplace [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
    let argValues :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
argValues =
            [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
                [ (Text
"str", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"search", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"replace", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                ]
                [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    in case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
argValues of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
strG, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
searchG, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
replaceG] -> do
            let str :: Text
str = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
strG
                search :: Text
search = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
searchG
                replace :: Text
replace = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
replaceG
            GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Text
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Text
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Text
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
Text.replace Text
search Text
replace Text
str
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"replace") Text
"expected: (str, search, replace)"

gfnSplit :: Monad m => Function (Run p m h)
gfnSplit :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnSplit [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
    let argValues :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
argValues =
            [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
                [ (Text
"str", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"sep", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                ]
                [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    in case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
argValues of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
strG, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sepG] -> do
            let search :: Text
search = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
strG
                split :: Text -> [Text]
split = case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sepG of
                    Text
"" -> Text -> [Text]
Text.words
                    Text
sep -> HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
Text.splitOn Text
sep
            GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Text
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Text
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([Text]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Text -> [Text])
-> Text
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
split (Text
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Text
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Text
search
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"split") Text
"expected: (str, sep=null)"

gfnCompose :: forall m p h. Monad m => Function (Run p m h)
gfnCompose :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnCompose [] = RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"compose") Text
""
gfnCompose [(Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fG)] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fG
gfnCompose ((Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fG):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
xs) = do
  GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gG <- Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnCompose [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
xs
  case (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fG, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gG) of
    (Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
Nothing, Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
_) -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError RuntimeError p
forall p. RuntimeError p
NotAFunctionError
    (Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
_, Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
Nothing) -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError RuntimeError p
forall p. RuntimeError p
NotAFunctionError
    (Just Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f, Just Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
g) -> do
      let h :: Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
h [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args = do
              GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
arg' <- Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
g [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
              Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f [(Maybe Text
forall a. Maybe a
Nothing, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
arg')]
      GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). Function m -> GVal m
fromFunction Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
h

gfnPartial :: forall m p h. Monad m => Function (Run p m h)
gfnPartial :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnPartial [] = RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"partial") Text
""
gfnPartial ((Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fG):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args) = do
  case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fG of
    Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
Nothing -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"partial") Text
"Argument must be a function"
    Just Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f -> do
      let h :: Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
h [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args' = do
            Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f ([(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a. [a] -> [a] -> [a]
++ [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args')
      GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). Function m -> GVal m
fromFunction Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
h

gfnZip :: forall m p h. Monad m => Function (Run p m h)
gfnZip :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnZip [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args = do
  [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
go (((Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe
   [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> ((Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Maybe
         [GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Maybe
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> ((Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd) [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args)
  where
    go :: [[GVal (Run p m h)]] -> Run p m h [GVal (Run p m h)]
    go :: [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
go [] = [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return []
    go [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
args = do
      let heads :: [Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
heads = ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> [Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a. [a] -> Maybe a
headMay [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
args
          tails :: [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
tails = ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. Int -> [a] -> [a]
List.drop Int
1) [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
args
      if (Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Bool)
-> [Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.any Maybe
  (GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Bool
forall a. Maybe a -> Bool
isNothing [Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
heads then
        [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return []
      else do
        let currentVal :: GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
currentVal = [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ((Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. a -> Maybe a -> a
fromMaybe GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def) [Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
heads)
        [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
tailVals <- [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
go [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
tails
        [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
currentVal GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. a -> [a] -> [a]
: [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
tailVals


gfnZipWith :: forall m p h. Monad m => Function (Run p m h)
gfnZipWith :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnZipWith ((Maybe Text
Nothing, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gfn):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args) = do
  Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
zipFunction <- case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gfn of
    Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
Nothing -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (Function
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"zipwith") Text
""
    Just Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fn -> Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fn
  [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [Maybe Text]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
go Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
zipFunction (((Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Maybe Text)
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [Maybe Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe Text
forall a b. (a, b) -> a
fst [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args) (((Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe
   [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> ((Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Maybe
         [GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Maybe
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> ((Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Maybe Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd) [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args)
  where
    go :: Function (Run p m h) -> [Maybe Text] -> [[GVal (Run p m h)]] -> Run p m h [GVal (Run p m h)]
    go :: Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [Maybe Text]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
go Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f [Maybe Text]
_ [] = [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return []
    go Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f [Maybe Text]
argNames [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
args = do
      let heads :: [Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
heads = ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> [Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a. [a] -> Maybe a
headMay [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
args
          tails :: [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
tails = ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. Int -> [a] -> [a]
List.drop Int
1) [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
args
      if (Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Bool)
-> [Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
List.any Maybe
  (GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Bool
forall a. Maybe a -> Bool
isNothing [Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
heads then
        [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return []
      else do
        GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
currentVal <- Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f ([Maybe Text]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. [a] -> [b] -> [(a, b)]
List.zip [Maybe Text]
argNames ((Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [Maybe
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. a -> Maybe a -> a
fromMaybe GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def) [Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
heads))
        [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
tailVals <- Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [Maybe Text]
-> [[GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
go Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f [Maybe Text]
argNames [[GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]]
tails
        [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
currentVal GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. a -> [a] -> [a]
: [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
tailVals


gfnMap :: (Monad m, MonadError (RuntimeError a) m) => Function m
gfnMap :: forall (m :: * -> *) a.
(Monad m, MonadError (RuntimeError a) m) =>
Function m
gfnMap [(Maybe Text, GVal m)]
args = do
    let parsedArgs :: Either ([GVal m], HashMap Text (GVal m), [Text]) [GVal m]
parsedArgs = [(Text, GVal m)]
-> [(Maybe Text, GVal m)]
-> Either ([GVal m], HashMap Text (GVal m), [Text]) [GVal m]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
            [ (Text
"collection", GVal m
forall a. Default a => a
def)
            , (Text
"function", GVal m
forall a. Default a => a
def)
            , (Text
"attribute", GVal m
forall a. Default a => a
def)
            ]
            [(Maybe Text, GVal m)]
args
    (Maybe [(Text, GVal m)]
dictMay, Maybe [GVal m]
listMay, Maybe (Function m)
functionMay, Maybe Text
attributeMay) <- case Either ([GVal m], HashMap Text (GVal m), [Text]) [GVal m]
parsedArgs of
        Right [GVal m
collection, GVal m
function, GVal m
attribute] ->
            (Maybe [(Text, GVal m)], Maybe [GVal m], Maybe (Function m),
 Maybe Text)
-> m (Maybe [(Text, GVal m)], Maybe [GVal m], Maybe (Function m),
      Maybe Text)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ( GVal m -> Maybe [(Text, GVal m)]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal m
collection
                   , GVal m -> Maybe [GVal m]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal m
collection
                   , GVal m -> Maybe (Function m)
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal m
function
                   , Text -> Maybe Text
forall a. a -> Maybe a
Just (GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText GVal m
attribute)
                   )
        Either ([GVal m], HashMap Text (GVal m), [Text]) [GVal m]
_ ->
            RuntimeError a
-> m (Maybe [(Text, GVal m)], Maybe [GVal m], Maybe (Function m),
      Maybe Text)
forall a. RuntimeError a -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError a
 -> m (Maybe [(Text, GVal m)], Maybe [GVal m], Maybe (Function m),
       Maybe Text))
-> RuntimeError a
-> m (Maybe [(Text, GVal m)], Maybe [GVal m], Maybe (Function m),
      Maybe Text)
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError a
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"map") Text
""
    Function m
mapFunction <- case (Maybe (Function m)
functionMay, Maybe Text
attributeMay) of
        (Just Function m
f, Maybe Text
_) -> Function m -> m (Function m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Function m
f
        (Maybe (Function m)
Nothing, Just Text
key) -> Function m -> m (Function m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Function m -> m (Function m)) -> Function m -> m (Function m)
forall a b. (a -> b) -> a -> b
$ \case
            (Maybe Text
_, GVal m
item):[(Maybe Text, GVal m)]
_ ->
                GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m)) -> GVal m -> m (GVal m)
forall a b. (a -> b) -> a -> b
$ GVal m -> GVal m -> GVal m -> GVal m
forall (m :: * -> *). GVal m -> GVal m -> GVal m -> GVal m
lookupLooseDef GVal m
forall a. Default a => a
def (Text -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Text
key) GVal m
item
            [(Maybe Text, GVal m)]
_ ->
                GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
forall a. Default a => a
def
        (Maybe (Function m), Maybe Text)
_ -> RuntimeError a -> m (Function m)
forall a. RuntimeError a -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError a -> m (Function m))
-> RuntimeError a -> m (Function m)
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError a
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"map") Text
"You have to pass a function or an attribute"
    case (Maybe [(Text, GVal m)]
dictMay, Maybe [GVal m]
listMay) of
        (Just [(Text, GVal m)]
items, Maybe [GVal m]
_) ->
            [(Text, GVal m)] -> GVal m
forall (m :: * -> *). [Pair m] -> GVal m
dict ([(Text, GVal m)] -> GVal m) -> m [(Text, GVal m)] -> m (GVal m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, GVal m)]
-> ((Text, GVal m) -> m (Text, GVal m)) -> m [(Text, GVal m)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Text, GVal m)]
items
                (\(Text
key, GVal m
value) -> (Text
key,) (GVal m -> (Text, GVal m)) -> m (GVal m) -> m (Text, GVal m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Function m
mapFunction [(Maybe Text
forall a. Maybe a
Nothing, GVal m
value)])
        (Maybe [(Text, GVal m)]
Nothing, Just [GVal m]
items) ->
            [GVal m] -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([GVal m] -> GVal m) -> m [GVal m] -> m (GVal m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GVal m -> m (GVal m)) -> [GVal m] -> m [GVal m]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Function m
mapFunction Function m
-> (GVal m -> [(Maybe Text, GVal m)]) -> GVal m -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Maybe Text, GVal m)
-> [(Maybe Text, GVal m)] -> [(Maybe Text, GVal m)]
forall a. a -> [a] -> [a]
:[]) ((Maybe Text, GVal m) -> [(Maybe Text, GVal m)])
-> (GVal m -> (Maybe Text, GVal m))
-> GVal m
-> [(Maybe Text, GVal m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Text
forall a. Maybe a
Nothing,)) [GVal m]
items
        (Maybe [(Text, GVal m)]
Nothing, Maybe [GVal m]
Nothing) ->
            GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
forall a. Default a => a
def

gfnReverse :: forall p m h. Monad m => Function (Run p m h)
gfnReverse :: forall p (m :: * -> *) h. Monad m => Function (Run p m h)
gfnReverse [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args = do
    let parsedArgs :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
parsedArgs = [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
            [ (Text
"reversee", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
            ]
            [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
reversee <- case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
parsedArgs of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
reversee] -> GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
reversee
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"reverse") Text
"expected: (reversee)"
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Maybe
      [GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe
   [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. [a] -> [a]
List.reverse ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> [GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
reversee
    

gfnSort :: forall p m h. Monad m => Function (Run p m h)
gfnSort :: forall p (m :: * -> *) h. Monad m => Function (Run p m h)
gfnSort [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args = do
    let parsedArgs :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
parsedArgs = [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
            [ (Text
"sortee", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
            , (Text
"by", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
            , (Text
"reverse", Bool
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
False)
            ]
            [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortee, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey, Bool
sortReverse) <- case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
parsedArgs of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortee, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
reverseG] ->
            (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
 Bool)
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
      Bool)
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return ( GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortee
                   , GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey
                   , GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
reverseG
                   )
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
      Bool)
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
       Bool))
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))),
      Bool)
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"sort") Text
"expected: (sortee, by, reverse)"
    let extractByFunc :: Maybe ((Text, GVal (Run p m h)) -> Run p m h (GVal (Run p m h)))
        extractByFunc :: Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByFunc = do
            Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f <- GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey
            ((Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (((Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
  -> Run
       p
       m
       h
       (GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> Maybe
      ((Text,
        GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
       -> Run
            p
            m
            h
            (GVal
               (ExceptT
                  (RuntimeError p)
                  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
-> ((Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Run
         p
         m
         h
         (GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a b. (a -> b) -> a -> b
$ \(Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
g ->
                Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
f [(Maybe Text
forall a. Maybe a
Nothing, (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
g)]

    let extractByPath :: Maybe ((Text, GVal (Run p m h)) -> Run p m h (GVal (Run p m h)))
        extractByPath :: Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByPath = do
            [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
keys <- GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey
            ((Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (((Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
  -> Run
       p
       m
       h
       (GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> Maybe
      ((Text,
        GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
       -> Run
            p
            m
            h
            (GVal
               (ExceptT
                  (RuntimeError p)
                  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
-> ((Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Run
         p
         m
         h
         (GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a b. (a -> b) -> a -> b
$ \(Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
g ->
                GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' ((GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b c. (a -> b -> c) -> b -> a -> c
flip (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). GVal m -> GVal m -> GVal m -> GVal m
lookupLooseDef GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)) ((Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
g) [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
keys

        extractByKey :: Monad m => Maybe ((Text, a) -> Run p m h (GVal (Run p m h)))
        extractByKey :: forall a.
Monad m =>
Maybe
  ((Text, a)
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByKey =
            if GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"__key"
                then ((Text, a)
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text, a)
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. a -> Maybe a
Just (((Text, a)
  -> Run
       p
       m
       h
       (GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> Maybe
      ((Text, a)
       -> Run
            p
            m
            h
            (GVal
               (ExceptT
                  (RuntimeError p)
                  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
-> ((Text, a)
    -> Run
         p
         m
         h
         (GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text, a)
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ((Text, a)
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Text, a)
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ((Text, a) -> Text)
-> (Text, a)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, a) -> Text
forall a b. (a, b) -> a
fst
                else Maybe
  ((Text, a)
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. Maybe a
Nothing

        extractByProp :: Maybe
  ((a,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByProp =
            if GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Bool
forall (m :: * -> *). GVal m -> Bool
isNull GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey
                then Maybe
  ((a,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. Maybe a
Nothing
                else ((a,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((a,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (((a,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
  -> Run
       p
       m
       h
       (GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> Maybe
      ((a,
        GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
       -> Run
            p
            m
            h
            (GVal
               (ExceptT
                  (RuntimeError p)
                  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
-> ((a,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Run
         p
         m
         h
         (GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((a,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ((a,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (a,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). GVal m -> GVal m -> GVal m -> GVal m
lookupLooseDef GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortKey (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ((a,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (a,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd

        extractFunc :: (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
extractFunc = ((Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a. a -> Maybe a -> a
fromMaybe (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ((Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd) (Maybe
   ((Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Run
         p
         m
         h
         (GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> (Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$
            Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByFunc Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
            Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByPath Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
            Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a.
Monad m =>
Maybe
  ((Text, a)
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByKey Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     ((Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
      -> Run
           p
           m
           h
           (GVal
              (ExceptT
                 (RuntimeError p)
                 (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
            Maybe
  ((Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall {a}.
Maybe
  ((a,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
   -> Run
        p
        m
        h
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
extractByProp

        ([Pair m] -> GVal m
pack, [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
unpacked) =
            case (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [(Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortee, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sortee) of
                (Just [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
dictItems, Maybe
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_) ->
                    ([Pair m] -> GVal m
forall (m :: * -> *). [Pair m] -> GVal m
orderedDict, [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
dictItems)
                (Maybe
  [(Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
Nothing, Just [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
listItems) ->
                    ([GVal m] -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([GVal m] -> GVal m)
-> ([Pair m] -> [GVal m]) -> [Pair m] -> GVal m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Pair m -> GVal m) -> [Pair m] -> [GVal m]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pair m -> GVal m
forall a b. (a, b) -> b
snd, [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a. [a] -> [(Text, a)]
listToIndexedDict [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
listItems)
                (Maybe
  [(Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
Nothing, Maybe
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
Nothing) ->
                    (GVal m -> [Pair m] -> GVal m
forall a b. a -> b -> a
Prelude.const GVal m
forall a. Default a => a
def, [])

    [(Text,
  (Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
tagged <- [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> ((Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
         (Text,
          (Text,
           GVal
             (ExceptT
                (RuntimeError p)
                (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [(Text,
       (Text,
        GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
unpacked (((Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
  -> ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
       (Text,
        (Text,
         GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      [(Text,
        (Text,
         GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))])
-> ((Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
         (Text,
          (Text,
           GVal
             (ExceptT
                (RuntimeError p)
                (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [(Text,
       (Text,
        GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
forall a b. (a -> b) -> a -> b
$ \(Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
item -> do
        GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
extracted <- (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
extractFunc (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
item
        (Text,
 (Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Text,
      (Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
extracted, (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
item)
    let compare :: (Text, c) -> (Text, d) -> Ordering
compare =
            (Text -> Text -> Ordering) -> (Text, c) -> (Text, d) -> Ordering
forall a b c d. (a -> a -> b) -> (a, c) -> (a, d) -> b
onFst ((Text -> Text -> Ordering) -> (Text, c) -> (Text, d) -> Ordering)
-> (Text -> Text -> Ordering) -> (Text, c) -> (Text, d) -> Ordering
forall a b. (a -> b) -> a -> b
$ if Bool
sortReverse
                then (Text -> Text -> Ordering) -> Text -> Text -> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare
                else Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare

    let sorted :: GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sorted = [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). [Pair m] -> GVal m
pack ([(Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ([(Text,
      (Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
    -> [(Text,
         GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))])
-> [(Text,
     (Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Text,
  (Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> (Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [(Text,
     (Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text,
 (Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a, b) -> b
snd ([(Text,
   (Text,
    GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [(Text,
     (Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a -> b) -> a -> b
$ ((Text,
  (Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> (Text,
     (Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
 -> Ordering)
-> [(Text,
     (Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
-> [(Text,
     (Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
List.sortBy (Text,
 (Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Text,
    (Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Ordering
forall {c} {d}. (Text, c) -> (Text, d) -> Ordering
compare [(Text,
  (Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))]
tagged

    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
sorted

onFst :: (a -> a -> b) -> (a, c) -> (a, d) -> b
onFst :: forall a b c d. (a -> a -> b) -> (a, c) -> (a, d) -> b
onFst a -> a -> b
f (a
x, c
_) (a
y, d
_) = a -> a -> b
f a
x a
y

listToIndexedDict :: [a] -> [(Text, a)]
listToIndexedDict :: forall a. [a] -> [(Text, a)]
listToIndexedDict [a]
values =
    let indexes :: [Text]
indexes = (Integer -> Text) -> [Integer] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Integer -> Text
forall a. Show a => a -> Text
tshow) [Integer
0..]
    in [Text] -> [a] -> [(Text, a)]
forall a b. [a] -> [b] -> [(a, b)]
List.zip [Text]
indexes [a]
values

center :: Text -> Prelude.Int -> Text -> Text
center :: Text -> Int -> Text -> Text
center Text
str Int
width Text
pad =
    if Text -> Int
Text.length Text
str Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
Prelude.>= Int
width
        then Text
str
        else Text
paddingL Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
str Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
paddingR
    where
        chars :: Int
chars = Int
width Int -> Int -> Int
forall a. Num a => a -> a -> a
- Text -> Int
Text.length Text
str
        charsL :: Int
charsL = Int
chars Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
        charsR :: Int
charsR = Int
chars Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
charsL
        repsL :: Int
repsL = Int -> Int
forall a. Enum a => a -> a
Prelude.succ Int
charsL Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Text -> Int
Text.length Text
pad
        paddingL :: Text
paddingL = Int -> Text -> Text
Text.take Int
charsL (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> Text
Text.replicate Int
repsL (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
pad
        repsR :: Int
repsR = Int -> Int
forall a. Enum a => a -> a
Prelude.succ Int
charsR Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Text -> Int
Text.length Text
pad
        paddingR :: Text
paddingR = Int -> Text -> Text
Text.take Int
charsR (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> Text
Text.replicate Int
repsR (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
pad

gfnFileSizeFormat :: Monad m => Function m
gfnFileSizeFormat :: forall (m :: * -> *). Monad m => Function m
gfnFileSizeFormat [(Maybe Text
_, GVal m
sizeG)] =
    Function m
forall (m :: * -> *). Monad m => Function m
gfnFileSizeFormat [(Maybe Text
forall a. Maybe a
Nothing, GVal m
sizeG), (Maybe Text
forall a. Maybe a
Nothing, GVal m
forall a. Default a => a
def)]
gfnFileSizeFormat [(Maybe Text
_, GVal m
sizeG), (Maybe Text
_, GVal m
binaryG)] = do
    let sizeM :: Maybe Integer
sizeM = Scientific -> Integer
forall b. Integral b => Scientific -> b
forall a b. (RealFrac a, Integral b) => a -> b
Prelude.round (Scientific -> Integer) -> Maybe Scientific -> Maybe Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Scientific
forall (m :: * -> *). GVal m -> Maybe Scientific
asNumber GVal m
sizeG
        binary :: Bool
binary = GVal m -> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal m
binaryG
    m (GVal m)
-> (Integer -> m (GVal m)) -> Maybe Integer -> m (GVal m)
forall b a. b -> (a -> b) -> Maybe a -> b
Prelude.maybe
        (GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
forall a. Default a => a
def)
        (GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal m -> m (GVal m))
-> (Integer -> GVal m) -> Integer -> m (GVal m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([Char] -> GVal m) -> (Integer -> [Char]) -> Integer -> GVal m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Integer -> [Char]
formatFileSize Bool
binary)
        Maybe Integer
sizeM
gfnFileSizeFormat [(Maybe Text, GVal m)]
_ = GVal m -> m (GVal m)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal m
forall a. Default a => a
def

formatFileSize :: Bool -> Integer -> String
formatFileSize :: Bool -> Integer -> [Char]
formatFileSize Bool
binary Integer
size =
    let units :: [(Integer, [Char])]
units =
            if Bool
binary
                then
                    [ (Integer
1, [Char]
"B")
                    , (Integer
1024, [Char]
"kiB")
                    , (Integer
1024 Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Integer
2, [Char]
"MiB")
                    , (Integer
1024 Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Integer
3, [Char]
"GiB")
                    , (Integer
1024 Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Integer
4, [Char]
"TiB")
                    , (Integer
1024 Integer -> Integer -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Integer
5, [Char]
"PiB")
                    ]
                else
                    [ (Integer
1, [Char]
"B")
                    , (Integer
1000, [Char]
"kB")
                    , (Integer
1000000, [Char]
"MB")
                    , (Integer
1000000000, [Char]
"GB")
                    , (Integer
1000000000000, [Char]
"TB")
                    , (Integer
1000000000000000, [Char]
"PB")
                    ]
        (Integer
divisor, [Char]
unitName) =
            (Integer, [Char]) -> [(Integer, [Char])] -> (Integer, [Char])
forall a. a -> [a] -> a
lastDef (Integer
1, [Char]
"B") [ (Integer
d, [Char]
u) | (Integer
d, [Char]
u) <- [(Integer, [Char])]
units, Integer
d Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
size ]
        dividedSize :: Scientific
        dividedSize :: Scientific
dividedSize = Integer -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
size Scientific -> Scientific -> Scientific
forall a. Fractional a => a -> a -> a
/ Integer -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
divisor
        formattedSize :: [Char]
formattedSize =
            if Scientific -> Bool
Scientific.isInteger Scientific
dividedSize
                then FPFormat -> Maybe Int -> Scientific -> [Char]
formatScientific FPFormat
Fixed (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0) Scientific
dividedSize
                else FPFormat -> Maybe Int -> Scientific -> [Char]
formatScientific FPFormat
Fixed (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
1) Scientific
dividedSize
    in [Char]
formattedSize [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
unitName

gfnPrintf :: Monad m => Function (Run p m h)
gfnPrintf :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnPrintf [] = do
    RuntimeError p -> Run p m h ()
forall (m :: * -> *) p h. Monad m => RuntimeError p -> Run p m h ()
warn (RuntimeError p -> Run p m h ()) -> RuntimeError p -> Run p m h ()
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"printf") Text
"No format string provided"
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def
gfnPrintf [(Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fmtStrG)] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fmtStrG
gfnPrintf ((Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fmtStrG):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args) = do
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ([Char]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [Char]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([Char]
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [Char]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [Char]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [Char]
forall (m :: * -> *). [Char] -> [GVal m] -> [Char]
printfG [Char]
fmtStr (((Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a b. (a, b) -> b
snd [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args)
    where
        fmtStr :: [Char]
fmtStr = Text -> [Char]
Text.unpack (Text -> [Char]) -> Text -> [Char]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
fmtStrG

gvalToDate :: TimeZone -> GVal m -> Maybe ZonedTime
gvalToDate :: forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalToDate TimeZone
tz GVal m
g = TimeZone -> GVal m -> Maybe ZonedTime
forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalDictToDate TimeZone
tz GVal m
g
             Maybe ZonedTime -> Maybe ZonedTime -> Maybe ZonedTime
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TimeZone -> GVal m -> Maybe ZonedTime
forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalListToDate TimeZone
tz GVal m
g
             Maybe ZonedTime -> Maybe ZonedTime -> Maybe ZonedTime
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TimeZone -> GVal m -> Maybe ZonedTime
forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalAutoParseDate TimeZone
tz GVal m
g

gvalDictToDate :: TimeZone -> GVal m -> Maybe ZonedTime
gvalDictToDate :: forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalDictToDate TimeZone
defTZ GVal m
g = do
    let datePartMay :: Maybe Day
datePartMay = do
            Integer
year <- (Int -> Integer) -> Maybe Int -> Maybe Integer
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral :: Int -> Integer) (Maybe Int -> Maybe Integer) -> Maybe Int -> Maybe Integer
forall a b. (a -> b) -> a -> b
$ GVal m
g GVal m -> GVal m -> Maybe Int
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"year"
            Int
month <- GVal m
g GVal m -> GVal m -> Maybe Int
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"month"
            Int
day <- GVal m
g GVal m -> GVal m -> Maybe Int
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"day"
            Day -> Maybe Day
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> Maybe Day) -> Day -> Maybe Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Int -> Day
fromGregorian Integer
year Int
month Int
day
        timePartMay :: Maybe TimeOfDay
timePartMay = do
            Int
hours <- GVal m
g GVal m -> GVal m -> Maybe Int
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"hours"
            Int
minutes <- GVal m
g GVal m -> GVal m -> Maybe Int
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"minutes"
            Pico
seconds <- (Scientific -> Pico) -> Maybe Scientific -> Maybe Pico
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Scientific -> Pico
scientificToPico (Maybe Scientific -> Maybe Pico) -> Maybe Scientific -> Maybe Pico
forall a b. (a -> b) -> a -> b
$ GVal m
g GVal m -> GVal m -> Maybe Scientific
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"seconds"
            TimeOfDay -> Maybe TimeOfDay
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> Maybe TimeOfDay) -> TimeOfDay -> Maybe TimeOfDay
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Pico -> TimeOfDay
TimeOfDay Int
hours Int
minutes Pico
seconds
        tzPartMay :: Maybe TimeZone
tzPartMay = GVal m
g GVal m -> GVal m -> Maybe TimeZone
forall (m :: * -> *) v. FromGVal m v => GVal m -> GVal m -> Maybe v
~! GVal m
"tz"
    Bool -> Maybe () -> Maybe ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Maybe Day -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Day
datePartMay Bool -> Bool -> Bool
&& Maybe TimeOfDay -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TimeOfDay
timePartMay) Maybe ()
forall a. Maybe a
Nothing
    let datePart :: Day
datePart = Day -> Maybe Day -> Day
forall a. a -> Maybe a -> a
fromMaybe (Integer -> Int -> Int -> Day
fromGregorian Integer
1970 Int
1 Int
1) Maybe Day
datePartMay
        timePart :: TimeOfDay
timePart = TimeOfDay -> Maybe TimeOfDay -> TimeOfDay
forall a. a -> Maybe a -> a
fromMaybe (Int -> Int -> Pico -> TimeOfDay
TimeOfDay Int
12 Int
0 Pico
0) Maybe TimeOfDay
timePartMay
        tz :: TimeZone
tz = TimeZone -> Maybe TimeZone -> TimeZone
forall a. a -> Maybe a -> a
fromMaybe TimeZone
defTZ Maybe TimeZone
tzPartMay
    ZonedTime -> Maybe ZonedTime
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> Maybe ZonedTime) -> ZonedTime -> Maybe ZonedTime
forall a b. (a -> b) -> a -> b
$ LocalTime -> TimeZone -> ZonedTime
ZonedTime (Day -> TimeOfDay -> LocalTime
LocalTime Day
datePart TimeOfDay
timePart) TimeZone
tz

gvalListToDate :: TimeZone -> GVal m -> Maybe ZonedTime
gvalListToDate :: forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalListToDate TimeZone
defTZ GVal m
g = [GVal m] -> Maybe ZonedTime
forall (m :: * -> *). [GVal m] -> Maybe ZonedTime
go ([GVal m] -> Maybe ZonedTime) -> Maybe [GVal m] -> Maybe ZonedTime
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GVal m -> Maybe [GVal m]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal m
g
    where
        go :: [GVal m] -> Maybe ZonedTime
        go :: forall (m :: * -> *). [GVal m] -> Maybe ZonedTime
go [GVal m]
parts = case [GVal m]
parts of
            [GVal m
yearG, GVal m
monthG, GVal m
dayG, GVal m
hoursG, GVal m
minutesG, GVal m
secondsG, GVal m
tzG] -> do
                Day
datePart <-
                    Integer -> Int -> Int -> Day
fromGregorian
                        (Integer -> Int -> Int -> Day)
-> Maybe Integer -> Maybe (Int -> Int -> Day)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> Maybe Int -> Maybe Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Int
forall (m :: * -> *). GVal m -> Maybe Int
toInt GVal m
yearG)
                        Maybe (Int -> Int -> Day) -> Maybe Int -> Maybe (Int -> Day)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Int
forall (m :: * -> *). GVal m -> Maybe Int
toInt GVal m
monthG
                        Maybe (Int -> Day) -> Maybe Int -> Maybe Day
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Int
forall (m :: * -> *). GVal m -> Maybe Int
toInt GVal m
dayG
                TimeOfDay
timePart <-
                    Int -> Int -> Pico -> TimeOfDay
TimeOfDay
                        (Int -> Int -> Pico -> TimeOfDay)
-> Maybe Int -> Maybe (Int -> Pico -> TimeOfDay)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Int
forall (m :: * -> *). GVal m -> Maybe Int
toInt GVal m
hoursG
                        Maybe (Int -> Pico -> TimeOfDay)
-> Maybe Int -> Maybe (Pico -> TimeOfDay)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GVal m -> Maybe Int
forall (m :: * -> *). GVal m -> Maybe Int
toInt GVal m
minutesG
                        Maybe (Pico -> TimeOfDay) -> Maybe Pico -> Maybe TimeOfDay
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> Pico
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Pico) -> Maybe Int -> Maybe Pico
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal m -> Maybe Int
forall (m :: * -> *). GVal m -> Maybe Int
toInt GVal m
secondsG)
                TimeZone
tzPart <- GVal m -> Maybe TimeZone
forall (m :: * -> *) a. FromGVal m a => GVal m -> Maybe a
fromGVal GVal m
tzG
                ZonedTime -> Maybe ZonedTime
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> Maybe ZonedTime) -> ZonedTime -> Maybe ZonedTime
forall a b. (a -> b) -> a -> b
$ LocalTime -> TimeZone -> ZonedTime
ZonedTime (Day -> TimeOfDay -> LocalTime
LocalTime Day
datePart TimeOfDay
timePart) TimeZone
tzPart
            [GVal m
yearG, GVal m
monthG, GVal m
dayG, GVal m
hoursG, GVal m
minutesG, GVal m
secondsG] ->
                [GVal m] -> Maybe ZonedTime
forall (m :: * -> *). [GVal m] -> Maybe ZonedTime
go [GVal m
yearG, GVal m
monthG, GVal m
dayG, GVal m
hoursG, GVal m
minutesG, GVal m
secondsG, TimeZone -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal TimeZone
defTZ]
            [GVal m
yearG, GVal m
monthG, GVal m
dayG, GVal m
hoursG, GVal m
minutesG] ->
                [GVal m] -> Maybe ZonedTime
forall (m :: * -> *). [GVal m] -> Maybe ZonedTime
go [GVal m
yearG, GVal m
monthG, GVal m
dayG, GVal m
hoursG, GVal m
minutesG, Int -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
0 :: Int)]
            [GVal m
yearG, GVal m
monthG, GVal m
dayG] ->
                [GVal m] -> Maybe ZonedTime
forall (m :: * -> *). [GVal m] -> Maybe ZonedTime
go [GVal m
yearG, GVal m
monthG, GVal m
dayG, Int -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
12 :: Int), Int -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Int
0 :: Int)]
            [GVal m]
_ -> Maybe ZonedTime
forall a. Maybe a
Nothing

gvalAutoParseDate :: TimeZone -> GVal m -> Maybe ZonedTime
gvalAutoParseDate :: forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalAutoParseDate TimeZone
defTZ = [Char] -> Maybe ZonedTime
go ([Char] -> Maybe ZonedTime)
-> (GVal m -> [Char]) -> GVal m -> Maybe ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
Text.unpack (Text -> [Char]) -> (GVal m -> Text) -> GVal m -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText
    where
        go :: [Char] -> Maybe ZonedTime
go [Char]
input = [Maybe ZonedTime] -> Maybe ZonedTime
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [ [Char] -> [Char] -> Maybe ZonedTime
parse [Char]
t [Char]
input | ([Char] -> [Char] -> Maybe ZonedTime
parse, [Char]
t) <- [([Char] -> [Char] -> Maybe ZonedTime, [Char])]
formats ]
        ztparse :: String -> String -> Maybe ZonedTime
        ztparse :: [Char] -> [Char] -> Maybe ZonedTime
ztparse [Char]
fmt = Bool -> TimeLocale -> [Char] -> [Char] -> Maybe ZonedTime
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> [Char] -> [Char] -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale [Char]
fmt
        utcparse :: String -> String -> Maybe ZonedTime
        utcparse :: [Char] -> [Char] -> Maybe ZonedTime
utcparse [Char]
fmt [Char]
input = do
            LocalTime
lt <- Bool -> TimeLocale -> [Char] -> [Char] -> Maybe LocalTime
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> [Char] -> [Char] -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale [Char]
fmt [Char]
input
            ZonedTime -> Maybe ZonedTime
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> Maybe ZonedTime) -> ZonedTime -> Maybe ZonedTime
forall a b. (a -> b) -> a -> b
$ LocalTime -> TimeZone -> ZonedTime
ZonedTime LocalTime
lt TimeZone
defTZ
        formats :: [([Char] -> [Char] -> Maybe ZonedTime, [Char])]
formats =
            [ ([Char] -> [Char] -> Maybe ZonedTime
ztparse, [Char]
"%Y-%m-%dT%H:%M:%S%Q%Z")
            , ([Char] -> [Char] -> Maybe ZonedTime
utcparse, [Char]
"%Y-%m-%d %H:%M:%S%Q")
            , ([Char] -> [Char] -> Maybe ZonedTime
ztparse, [Char]
"%Y-%m-%d %H:%M:%S%Q%z")
            , ([Char] -> [Char] -> Maybe ZonedTime
ztparse, [Char]
"%Y-%m-%d %H:%M:%S%Q%Z")
            , ([Char] -> [Char] -> Maybe ZonedTime
utcparse, [Char]
"%Y-%m-%d")
            ]

gvalToTZ :: GVal m -> Maybe TimeZone
gvalToTZ :: forall (m :: * -> *). GVal m -> Maybe TimeZone
gvalToTZ GVal m
g =
    GVal m -> Maybe TimeZone
forall (m :: * -> *) a. FromGVal m a => GVal m -> Maybe a
fromGVal GVal m
g Maybe TimeZone -> Maybe TimeZone -> Maybe TimeZone
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ([Char] -> Maybe TimeZone
parseTZ ([Char] -> Maybe TimeZone)
-> (GVal m -> [Char]) -> GVal m -> Maybe TimeZone
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
Text.unpack (Text -> [Char]) -> (GVal m -> Text) -> GVal m -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal m -> Maybe TimeZone) -> GVal m -> Maybe TimeZone
forall a b. (a -> b) -> a -> b
$ GVal m
g)

parseTZ :: String -> Maybe TimeZone
parseTZ :: [Char] -> Maybe TimeZone
parseTZ = Bool -> TimeLocale -> [Char] -> [Char] -> Maybe TimeZone
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> [Char] -> [Char] -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale [Char]
"%z"

gfnDateFormat :: Monad m => Function (Run p m h)
gfnDateFormat :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnDateFormat [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
    let extracted :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
extracted =
            [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
                [ (Text
"date", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"format", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"tz", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"locale", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                ]
                [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    in case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
extracted of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gDate, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gFormat, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gTimeZone, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gLocale] ->
                -- The desired target timezone; Nothing means keep original timezone
            let tzMay :: Maybe TimeZone
tzMay = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe TimeZone
forall (m :: * -> *). GVal m -> Maybe TimeZone
gvalToTZ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gTimeZone
                -- The default timezone used when the input doesn't include timezone
                -- information; if a target timezone is given, then it is also used as
                -- the default, otherwise, UTC is assumed. The underlying assumptions
                -- are:
                --
                -- * If the input does not include timezone information, then it is a
                --   local time; hence, if the user explicitly passes a time zone for
                --   formatting, it is assumed that this means the original local time
                --   is in that time zone.
                -- * If the input does not include timezone information, and no
                --   explicit timezone is given, the only sane time zone to pick is
                --   UTC. In this situation, the incoming dates either originate from
                --   a system that doesn't track timezone information but implicitly
                --   stores everything in UTC (which is fine), or the formatting
                --   doesn't use timezone information anyway (in which case it doesn't
                --   matter), or the originator of the data uses another timezone but
                --   fails to report it (in which case it is impossible to do the right
                --   thing)
                -- * If the input *does* include timezone information, it should be
                --   respected; explicitly passing timezone information in the date()
                --   call means the user wants to represent the same zoned time in a
                --   different time zone, which means time zone conversion is required.
                defTZ :: TimeZone
defTZ = TimeZone -> Maybe TimeZone -> TimeZone
forall a. a -> Maybe a -> a
fromMaybe TimeZone
utc Maybe TimeZone
tzMay
                dateMay :: Maybe ZonedTime
dateMay = TimeZone
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe ZonedTime
forall (m :: * -> *). TimeZone -> GVal m -> Maybe ZonedTime
gvalToDate TimeZone
defTZ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gDate
                fmtMay :: Maybe [Char]
fmtMay = Text -> [Char]
Text.unpack (Text -> [Char]) -> Maybe Text -> Maybe [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe Text
forall (m :: * -> *) a. FromGVal m a => GVal m -> Maybe a
fromGVal GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gFormat
            in case Maybe [Char]
fmtMay of
                Just [Char]
fmt -> do
                    TimeLocale
locale <- ExceptT
  (RuntimeError p)
  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
  TimeLocale
-> (TimeLocale
    -> ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
         TimeLocale)
-> Maybe TimeLocale
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     TimeLocale
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
                        (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     TimeLocale
forall (m :: * -> *) p h.
Monad m =>
GVal (Run p m h) -> Run p m h TimeLocale
getTimeLocale GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gLocale)
                        TimeLocale
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     TimeLocale
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return
                        (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe TimeLocale
forall (m :: * -> *) a. FromGVal m a => GVal m -> Maybe a
fromGVal GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gLocale)
                    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Maybe [Char]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe [Char]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe [Char]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe [Char]
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe [Char]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ TimeLocale -> [Char] -> ZonedTime -> [Char]
forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
formatTime TimeLocale
locale [Char]
fmt (ZonedTime -> [Char])
-> (ZonedTime -> ZonedTime) -> ZonedTime -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe TimeZone -> ZonedTime -> ZonedTime
convertTZ Maybe TimeZone
tzMay (ZonedTime -> [Char]) -> Maybe ZonedTime -> Maybe [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ZonedTime
dateMay
                Maybe [Char]
Nothing -> do
                    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Maybe ZonedTime
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe ZonedTime
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe ZonedTime
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe ZonedTime
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe ZonedTime
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe TimeZone -> ZonedTime -> ZonedTime
convertTZ Maybe TimeZone
tzMay (ZonedTime -> ZonedTime) -> Maybe ZonedTime -> Maybe ZonedTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ZonedTime
dateMay
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"date") Text
"expected: (date, format, tz=null, locale=null)"
    where
        convertTZ :: Maybe TimeZone -> ZonedTime -> ZonedTime
        convertTZ :: Maybe TimeZone -> ZonedTime -> ZonedTime
convertTZ Maybe TimeZone
Nothing = ZonedTime -> ZonedTime
forall a. a -> a
id
        convertTZ (Just TimeZone
tz) = TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
tz (UTCTime -> ZonedTime)
-> (ZonedTime -> UTCTime) -> ZonedTime -> ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC

getTimeLocale :: Monad m => GVal (Run p m h) -> Run p m h TimeLocale
getTimeLocale :: forall (m :: * -> *) p h.
Monad m =>
GVal (Run p m h) -> Run p m h TimeLocale
getTimeLocale GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
localeName = do
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
toFunction (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Maybe
      (Function
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Maybe
        (Function
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h.
Monad m =>
Text -> Run p m h (GVal (Run p m h))
getVar Text
"getlocale" ExceptT
  (RuntimeError p)
  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
  (Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (Maybe
      (Function
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
    -> Run p m h TimeLocale)
-> Run p m h TimeLocale
forall a b.
ExceptT
  (RuntimeError p)
  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
  a
-> (a
    -> ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
         b)
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Maybe
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
Nothing ->
            TimeLocale -> Run p m h TimeLocale
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return TimeLocale
defaultTimeLocale
        Just Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
getlocale -> do
            let args :: [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args = [ (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"category", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
"LC_TIME")
                       , (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"locale", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
localeName)
                       ]
            TimeLocale -> Maybe TimeLocale -> TimeLocale
forall a. a -> Maybe a -> a
fromMaybe TimeLocale
defaultTimeLocale (Maybe TimeLocale -> TimeLocale)
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Maybe TimeLocale)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> TimeLocale
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe TimeLocale
forall (m :: * -> *) a. FromGVal m a => GVal m -> Maybe a
fromGVal (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> TimeLocale)
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run p m h TimeLocale
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
getlocale [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args


gfnFilter :: Monad m => Function (Run p m h)
gfnFilter :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnFilter [] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def
gfnFilter [(Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
xs)] = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
xs
gfnFilter ((Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
xs):(Maybe Text
_, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
p):[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args) = do
    Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
pfnG <- ExceptT
  (RuntimeError p)
  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
  (Function
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Function
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
         (Function
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError RuntimeError p
forall p. RuntimeError p
NotAFunctionError) Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     (Function
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *). GVal m -> Maybe (Function m)
asFunction GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
p)
    let pfn :: GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run p m h Bool
pfn GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
x = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Bool)
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Run p m h Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Function
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
pfnG ((Maybe Text
forall a. Maybe a
Nothing, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
x)(Maybe Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a. a -> [a] -> [a]
:[(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args)
        xsl :: [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
xsl = [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a. a -> Maybe a -> a
fromMaybe [] (GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *). GVal m -> Maybe [GVal m]
asList GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
xs)
    [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
filtered <- (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run p m h Bool)
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run p m h Bool
pfn [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
xsl
    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
filtered

printfG :: String -> [GVal m] -> String
printfG :: forall (m :: * -> *). [Char] -> [GVal m] -> [Char]
printfG [Char]
fmt [GVal m]
args = [Char] -> [PrintfArgT] -> [Char]
forall t. PrintfType t => [Char] -> [PrintfArgT] -> t
printfa [Char]
fmt ((GVal m -> PrintfArgT) -> [GVal m] -> [PrintfArgT]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GVal m -> PrintfArgT
forall a. PrintfArg a => a -> PrintfArgT
P [GVal m]
args)


gfnDictsort :: Monad m => Function (Run p m h)
gfnDictsort :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnDictsort [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
    let extracted :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
extracted =
            [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
                [ (Text
"dict", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"case_sensitive", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
                , (Text
"by", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
"key")
                ]
                [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
    in case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
extracted of
        Right [GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gDict, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gCaseSensitive, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gSortBy] -> do
            let caseSensitive :: Bool
caseSensitive = GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gCaseSensitive
            Bool
sortByKey <- case GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gSortBy of
                Text
"key" -> Bool
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
                Text
"value" -> Bool
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
                Text
"val" -> Bool
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
                Text
x -> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
forall a.
RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      Bool)
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"dictsort")
                        ( Text
"argument 'by' must be one of 'key', 'value', 'val', " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                          Text
"but found '" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                          Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"'"
                        )
            let items :: [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
items = [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Maybe
     [(Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe
   [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
 -> [(Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))])
-> Maybe
     [(Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Maybe
     [(Text,
       GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall (m :: * -> *). GVal m -> Maybe [(Text, GVal m)]
asDictItems GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gDict
            let projection :: (Text, GVal m) -> Text
projection =
                    (if Bool
caseSensitive then Text -> Text
forall a. a -> a
id else Text -> Text
Text.toUpper) (Text -> Text)
-> ((Text, GVal m) -> Text) -> (Text, GVal m) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                    (if Bool
sortByKey then (Text, GVal m) -> Text
forall a b. (a, b) -> a
fst else (GVal m -> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal m -> Text)
-> ((Text, GVal m) -> GVal m) -> (Text, GVal m) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, GVal m) -> GVal m
forall a b. (a, b) -> b
snd))
            GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> ([(Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). [Pair m] -> GVal m
orderedDict ([(Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ([(Text,
      GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
    -> [(Text,
         GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))])
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> Text)
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
forall b a. Ord b => (a -> b) -> [a] -> [a]
List.sortOn (Text,
 GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Text
forall {m :: * -> *}. (Text, GVal m) -> Text
projection ([(Text,
   GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> [(Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
items
        Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"dictsort") Text
"expected: (dict, case_sensitive=false, by=null)"

gfnJSON :: Monad m => Function (Run p m h)
gfnJSON :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnJSON [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
  let extracted :: Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
extracted =
          [(Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> Either
     ([GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
      HashMap
        Text
        (GVal
           (ExceptT
              (RuntimeError p)
              (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
      [Text])
     [GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a.
[(Text, a)]
-> [(Maybe Text, a)] -> Either ([a], HashMap Text a, [Text]) [a]
extractArgsDefL
            [ (Text
"val", GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall a. Default a => a
def)
            , (Text
"pretty", Bool
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal Bool
True)
            ]
            [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args
  in case Either
  ([GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
   HashMap
     Text
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
   [Text])
  [GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
extracted of
      Right [ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gVal, GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gPretty ] -> do
          let encoder :: GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ByteString
encoder =
                if GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Bool
forall (m :: * -> *). GVal m -> Bool
asBoolean GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gPretty then
                    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ByteString
forall a. ToJSON a => a -> ByteString
JSON.encodePretty
                else
                    GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ByteString
forall a. ToJSON a => a -> ByteString
JSON.encode
          GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            Text
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Text
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Text)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            [Char] -> Text
Text.pack ([Char] -> Text)
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> [Char])
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            ByteString -> [Char]
UTF8.toString (ByteString -> [Char])
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> ByteString)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            ByteString -> ByteString
LBS.toStrict (ByteString -> ByteString)
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> ByteString)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> ByteString
encoder (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$
            GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
gVal
      Left ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))],
 HashMap
   Text
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))),
 [Text])
_ -> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> Run
      p
      m
      h
      (GVal
         (ExceptT
            (RuntimeError p)
            (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> RuntimeError p
-> Run
     p
     m
     h
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"json") Text
"expected: one argument"


-- Built-in tests
--gfnDefined :: Monad m => Function (Run p m h)
--gfnDefined = unaryFunc $ toGVal . isJust . fmap getVar . fromGVal

gfnDivisibleBy :: Monad m => Function (Run p m h)
gfnDivisibleBy :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnDivisibleBy = (GVal (Run p m h) -> GVal (Run p m h) -> GVal (Run p m h))
-> Function (Run p m h)
forall (m :: * -> *) h p.
Monad m =>
(GVal (Run p m h) -> GVal (Run p m h) -> GVal (Run p m h))
-> Function (Run p m h)
binaryFunc ((GVal (Run p m h) -> GVal (Run p m h) -> GVal (Run p m h))
 -> Function (Run p m h))
-> (GVal (Run p m h) -> GVal (Run p m h) -> GVal (Run p m h))
-> Function (Run p m h)
forall a b. (a -> b) -> a -> b
$ \GVal (Run p m h)
x GVal (Run p m h)
y -> Maybe Bool -> GVal (Run p m h)
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe Bool -> GVal (Run p m h)) -> Maybe Bool -> GVal (Run p m h)
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> Bool
forall {a}. Integral a => a -> a -> Bool
divisibleBy (Integer -> Integer -> Bool)
-> Maybe Integer -> Maybe (Integer -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GVal (Run p m h) -> Maybe Integer
forall (m :: * -> *). GVal m -> Maybe Integer
toInteger GVal (Run p m h)
x) Maybe (Integer -> Bool) -> Maybe Integer -> Maybe Bool
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GVal (Run p m h) -> Maybe Integer
forall (m :: * -> *). GVal m -> Maybe Integer
toInteger GVal (Run p m h)
y)
  where divisibleBy :: a -> a -> Bool
divisibleBy a
x a
y = a
x a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.mod` a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0

gfnEven :: Monad m => Function (Run p m h)
gfnEven :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnEven = (GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
forall (m :: * -> *) h p.
Monad m =>
(GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
unaryFunc ((GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h))
-> (GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
forall a b. (a -> b) -> a -> b
$ Maybe Bool -> GVal (Run p m h)
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe Bool -> GVal (Run p m h))
-> (GVal (Run p m h) -> Maybe Bool)
-> GVal (Run p m h)
-> GVal (Run p m h)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Bool) -> Maybe Integer -> Maybe Bool
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Bool
forall a. Integral a => a -> Bool
Prelude.even (Maybe Integer -> Maybe Bool)
-> (GVal (Run p m h) -> Maybe Integer)
-> GVal (Run p m h)
-> Maybe Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal (Run p m h) -> Maybe Integer
forall (m :: * -> *). GVal m -> Maybe Integer
toInteger

gfnOdd :: Monad m => Function (Run p m h)
gfnOdd :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnOdd = (GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
forall (m :: * -> *) h p.
Monad m =>
(GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
unaryFunc ((GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h))
-> (GVal (Run p m h) -> GVal (Run p m h)) -> Function (Run p m h)
forall a b. (a -> b) -> a -> b
$ Maybe Bool -> GVal (Run p m h)
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe Bool -> GVal (Run p m h))
-> (GVal (Run p m h) -> Maybe Bool)
-> GVal (Run p m h)
-> GVal (Run p m h)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Bool) -> Maybe Integer -> Maybe Bool
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Bool
forall a. Integral a => a -> Bool
Prelude.odd (Maybe Integer -> Maybe Bool)
-> (GVal (Run p m h) -> Maybe Integer)
-> GVal (Run p m h)
-> Maybe Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal (Run p m h) -> Maybe Integer
forall (m :: * -> *). GVal m -> Maybe Integer
toInteger

gfoRegex :: Monad m => GVal (Run p m h)
gfoRegex :: forall (m :: * -> *) p h. Monad m => GVal (Run p m h)
gfoRegex =
  [Pair (Run p m h)] -> GVal (Run p m h)
forall (m :: * -> *). [Pair m] -> GVal m
dict
    [ (Text
"match", Function (Run p m h) -> GVal (Run p m h)
forall (m :: * -> *). Function m -> GVal m
fromFunction Function (Run p m h)
forall p (m :: * -> *) h. Monad m => Function (Run p m h)
gfnReMatchOne)
    , (Text
"matches", Function (Run p m h) -> GVal (Run p m h)
forall (m :: * -> *). Function m -> GVal m
fromFunction Function (Run p m h)
forall p (m :: * -> *) h. Monad m => Function (Run p m h)
gfnReMatch)
    , (Text
"test", Function (Run p m h) -> GVal (Run p m h)
forall (m :: * -> *). Function m -> GVal m
fromFunction Function (Run p m h)
forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnReTest)
    ]

gfnReMatchOne :: forall p m h. Monad m => Function (Run p m h)
gfnReMatchOne :: forall p (m :: * -> *) h. Monad m => Function (Run p m h)
gfnReMatchOne [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
  Maybe
  (GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Maybe
   (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> (Maybe ([Char], MatchText [Char], [Char])
    -> Maybe
         (GVal
            (ExceptT
               (RuntimeError p)
               (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))))
-> Maybe ([Char], MatchText [Char], [Char])
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([Char], MatchText [Char], [Char])
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> Maybe ([Char], MatchText [Char], [Char])
-> Maybe
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\([Char]
_, MatchText [Char]
m, [Char]
_) -> MatchText [Char]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). Monad m => MatchText [Char] -> GVal m
matchTextToGVal MatchText [Char]
m :: GVal (Run p m h)) (Maybe ([Char], MatchText [Char], [Char])
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Maybe ([Char], MatchText [Char], [Char]))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Regex -> [Char] -> Maybe ([Char], MatchText [Char], [Char]))
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (Maybe ([Char], MatchText [Char], [Char]))
forall {m :: * -> *} {a} {p} {h}.
Monad m =>
(Regex -> [Char] -> a)
-> [(Maybe Text, GVal (Run p m h))] -> Run p m h a
fnReMatch Regex -> [Char] -> Maybe ([Char], MatchText [Char], [Char])
forall regex source.
RegexLike regex source =>
regex -> source -> Maybe (source, MatchText source, source)
RE.matchOnceText [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args

gfnReMatch :: forall p m h. Monad m => Function (Run p m h)
gfnReMatch :: forall p (m :: * -> *) h. Monad m => Function (Run p m h)
gfnReMatch [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
  [GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ([MatchText [Char]]
    -> [GVal
          (ExceptT
             (RuntimeError p)
             (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))])
-> [MatchText [Char]]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MatchText [Char]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> [MatchText [Char]]
-> [GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (MatchText [Char]
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *). Monad m => MatchText [Char] -> GVal m
matchTextToGVal :: RE.MatchText String -> GVal (Run p m h)) ([MatchText [Char]]
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [MatchText [Char]]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Regex -> [Char] -> [MatchText [Char]])
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     [MatchText [Char]]
forall {m :: * -> *} {a} {p} {h}.
Monad m =>
(Regex -> [Char] -> a)
-> [(Maybe Text, GVal (Run p m h))] -> Run p m h a
fnReMatch Regex -> [Char] -> [MatchText [Char]]
forall regex source.
RegexLike regex source =>
regex -> source -> [MatchText source]
RE.matchAllText [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args

gfnReTest :: Monad m => Function (Run p m h)
gfnReTest :: forall (m :: * -> *) p h. Monad m => Function (Run p m h)
gfnReTest [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args =
  Bool
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal (Bool
 -> GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     (GVal
        (ExceptT
           (RuntimeError p)
           (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Regex -> [Char] -> Bool)
-> [(Maybe Text,
     GVal
       (ExceptT
          (RuntimeError p)
          (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     Bool
forall {m :: * -> *} {a} {p} {h}.
Monad m =>
(Regex -> [Char] -> a)
-> [(Maybe Text, GVal (Run p m h))] -> Run p m h a
fnReMatch Regex -> [Char] -> Bool
forall regex source.
RegexLike regex source =>
regex -> source -> Bool
RE.matchTest [(Maybe Text,
  GVal
    (ExceptT
       (RuntimeError p)
       (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))))]
args

matchTextToGVal :: Monad m => RE.MatchText String -> GVal m
matchTextToGVal :: forall (m :: * -> *). Monad m => MatchText [Char] -> GVal m
matchTextToGVal MatchText [Char]
matchArr =
  let base :: GVal m
base = [Text] -> GVal m
forall (m :: * -> *) a. ToGVal m a => a -> GVal m
toGVal ([Text] -> GVal m)
-> (MatchText [Char] -> [Text]) -> MatchText [Char] -> GVal m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array Int Text -> [Text]
forall a. Array Int a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Array Int Text -> [Text])
-> (MatchText [Char] -> Array Int Text)
-> MatchText [Char]
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([Char], (Int, Int)) -> Text)
-> MatchText [Char] -> Array Int Text
forall a b. (a -> b) -> Array Int a -> Array Int b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> Text
Text.pack ([Char] -> Text)
-> (([Char], (Int, Int)) -> [Char]) -> ([Char], (Int, Int)) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], (Int, Int)) -> [Char]
forall a b. (a, b) -> a
fst) (MatchText [Char] -> GVal m) -> MatchText [Char] -> GVal m
forall a b. (a -> b) -> a -> b
$ MatchText [Char]
matchArr
      textRepr :: Text
textRepr = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Text)
-> (MatchText [Char] -> Maybe Text) -> MatchText [Char] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([Char], (Int, Int)) -> Text)
-> Maybe ([Char], (Int, Int)) -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> Text
Text.pack ([Char] -> Text)
-> (([Char], (Int, Int)) -> [Char]) -> ([Char], (Int, Int)) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], (Int, Int)) -> [Char]
forall a b. (a, b) -> a
fst) (Maybe ([Char], (Int, Int)) -> Maybe Text)
-> (MatchText [Char] -> Maybe ([Char], (Int, Int)))
-> MatchText [Char]
-> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [([Char], (Int, Int))] -> Maybe ([Char], (Int, Int))
forall a. [a] -> Maybe a
headMay ([([Char], (Int, Int))] -> Maybe ([Char], (Int, Int)))
-> (MatchText [Char] -> [([Char], (Int, Int))])
-> MatchText [Char]
-> Maybe ([Char], (Int, Int))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatchText [Char] -> [([Char], (Int, Int))]
forall a. Array Int a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (MatchText [Char] -> Text) -> MatchText [Char] -> Text
forall a b. (a -> b) -> a -> b
$ MatchText [Char]
matchArr
  in GVal m
forall {m :: * -> *}. GVal m
base
      { asText = textRepr
      , asHtml = html textRepr
      }

fnReMatch :: (Regex -> [Char] -> a)
-> [(Maybe Text, GVal (Run p m h))] -> Run p m h a
fnReMatch Regex -> [Char] -> a
matchFunc [(Maybe Text, GVal (Run p m h))]
args =
  let gArgs :: Either
  ([GVal (Run p m h)], HashMap Text (GVal (Run p m h)), [Text])
  [Maybe (GVal (Run p m h))]
gArgs = [Text]
-> [(Maybe Text, GVal (Run p m h))]
-> Either
     ([GVal (Run p m h)], HashMap Text (GVal (Run p m h)), [Text])
     [Maybe (GVal (Run p m h))]
forall a.
[Text]
-> [(Maybe Text, a)]
-> Either ([a], HashMap Text a, [Text]) [Maybe a]
extractArgsL [Text
"re", Text
"haystack", Text
"opts"] [(Maybe Text, GVal (Run p m h))]
args
  in (([GVal (Run p m h)], HashMap Text (GVal (Run p m h)), [Text])
 -> Run p m h a)
-> ([Maybe (GVal (Run p m h))] -> Run p m h a)
-> Either
     ([GVal (Run p m h)], HashMap Text (GVal (Run p m h)), [Text])
     [Maybe (GVal (Run p m h))]
-> Run p m h a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Run p m h a
-> ([GVal (Run p m h)], HashMap Text (GVal (Run p m h)), [Text])
-> Run p m h a
forall a b. a -> b -> a
const Run p m h a
forall {p} {h} {a}. Run p m h a
barf) [Maybe (GVal (Run p m h))] -> Run p m h a
forall {p} {h}.
[Maybe (GVal (Run p m h))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
go Either
  ([GVal (Run p m h)], HashMap Text (GVal (Run p m h)), [Text])
  [Maybe (GVal (Run p m h))]
gArgs
  where
    go :: [Maybe (GVal (Run p m h))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
go = \case
      [Maybe (GVal (Run p m h))
r, Maybe (GVal (Run p m h))
h, Maybe (GVal (Run p m h))
Nothing] ->
        [Maybe (GVal (Run p m h))]
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
go [Maybe (GVal (Run p m h))
r, Maybe (GVal (Run p m h))
h, GVal (Run p m h) -> Maybe (GVal (Run p m h))
forall a. a -> Maybe a
Just GVal (Run p m h)
forall a. Default a => a
def]
      [Just GVal (Run p m h)
reG, Just GVal (Run p m h)
haystackG, Just GVal (Run p m h)
optsG] -> do
        CompOption
opts <- GVal (Run p m h) -> Run p m h CompOption
forall (m :: * -> *) p h.
Monad m =>
GVal (Run p m h) -> Run p m h CompOption
parseCompOpts GVal (Run p m h)
optsG
        let reM :: Either [Char] Regex
reM = FailToEither Regex -> Either [Char] Regex
forall a. FailToEither a -> Either [Char] a
runFailToEither (FailToEither Regex -> Either [Char] Regex)
-> FailToEither Regex -> Either [Char] Regex
forall a b. (a -> b) -> a -> b
$
                      CompOption -> ExecOption -> [Char] -> FailToEither Regex
forall regex compOpt execOpt source (m :: * -> *).
(RegexMaker regex compOpt execOpt source, MonadFail m) =>
compOpt -> execOpt -> source -> m regex
forall (m :: * -> *).
MonadFail m =>
CompOption -> ExecOption -> [Char] -> m Regex
RE.makeRegexOptsM CompOption
opts ExecOption
forall regex compOpt execOpt.
RegexOptions regex compOpt execOpt =>
execOpt
RE.defaultExecOpt (Text -> [Char]
Text.unpack (Text -> [Char])
-> (GVal (Run p m h) -> Text) -> GVal (Run p m h) -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal (Run p m h) -> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal (Run p m h) -> [Char]) -> GVal (Run p m h) -> [Char]
forall a b. (a -> b) -> a -> b
$ GVal (Run p m h)
reG)
            haystack :: [Char]
haystack = Text -> [Char]
Text.unpack (Text -> [Char])
-> (GVal (Run p m h) -> Text) -> GVal (Run p m h) -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal (Run p m h) -> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal (Run p m h) -> [Char]) -> GVal (Run p m h) -> [Char]
forall a b. (a -> b) -> a -> b
$ GVal (Run p m h)
haystackG
        case Either [Char] Regex
reM of
            Left [Char]
err ->
                RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      a)
-> RuntimeError p
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"re.match") (Text -> RuntimeError p) -> Text -> RuntimeError p
forall a b. (a -> b) -> a -> b
$ Text
"invalid regex: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Char] -> Text
Text.pack [Char]
err
            Right Regex
re ->
                a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
 -> ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
      a)
-> a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall a b. (a -> b) -> a -> b
$ Regex -> [Char] -> a
matchFunc Regex
re [Char]
haystack
      [Maybe (GVal (Run p m h))]
_ -> ExceptT
  (RuntimeError p)
  (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
  a
forall {p} {h} {a}. Run p m h a
barf
    barf :: Run p m h a
barf = do
      RuntimeError p -> Run p m h a
forall (m :: * -> *) p h a.
Monad m =>
RuntimeError p -> Run p m h a
throwHere (RuntimeError p -> Run p m h a) -> RuntimeError p -> Run p m h a
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"re.match") Text
"expected: regex, haystack, [opts]"

parseCompOpts :: Monad m => GVal (Run p m h) -> Run p m h RE.CompOption
parseCompOpts :: forall (m :: * -> *) p h.
Monad m =>
GVal (Run p m h) -> Run p m h CompOption
parseCompOpts GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
g = do
  let str :: [Char]
str = Text -> [Char]
Text.unpack (Text -> [Char])
-> (GVal
      (ExceptT
         (RuntimeError p)
         (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
    -> Text)
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> Text
forall (m :: * -> *). GVal m -> Text
asText (GVal
   (ExceptT
      (RuntimeError p)
      (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
 -> [Char])
-> GVal
     (ExceptT
        (RuntimeError p)
        (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
-> [Char]
forall a b. (a -> b) -> a -> b
$ GVal
  (ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m)))
g
  (CompOption -> Char -> Run p m h CompOption)
-> CompOption -> [Char] -> Run p m h CompOption
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM
    (\CompOption
x ->
      \case
        Char
'i' -> CompOption -> Run p m h CompOption
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return CompOption
x { RE.caseSensitive = False }
        Char
'm' -> CompOption -> Run p m h CompOption
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return CompOption
x { RE.multiline = True }
        Char
c -> do
          RuntimeError p -> Run p m h ()
forall (m :: * -> *) p h. Monad m => RuntimeError p -> Run p m h ()
warn (RuntimeError p -> Run p m h ()) -> RuntimeError p -> Run p m h ()
forall a b. (a -> b) -> a -> b
$ Maybe Text -> Text -> RuntimeError p
forall p. Maybe Text -> Text -> RuntimeError p
ArgumentsError Maybe Text
forall a. Maybe a
Nothing (Text -> RuntimeError p) -> Text -> RuntimeError p
forall a b. (a -> b) -> a -> b
$ Text
"unexpected regex modifier: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Char -> Text
forall a. Show a => a -> Text
tshow Char
c
          CompOption -> Run p m h CompOption
forall a.
a
-> ExceptT
     (RuntimeError p)
     (StateT (RunState p m h) (ReaderT (GingerContext p m h) m))
     a
forall (m :: * -> *) a. Monad m => a -> m a
return CompOption
x
    )
    CompOption
forall regex compOpt execOpt.
RegexOptions regex compOpt execOpt =>
compOpt
RE.blankCompOpt
    [Char]
str

-- | This type provides an easy way to use 'RE.makeRegexOptsM' without having
-- to add a new dependency.
newtype FailToEither a
  = FailToEither
      { forall a. FailToEither a -> Either [Char] a
runFailToEither :: Either String a
      }
  deriving newtype (Functor FailToEither
Functor FailToEither =>
(forall a. a -> FailToEither a)
-> (forall a b.
    FailToEither (a -> b) -> FailToEither a -> FailToEither b)
-> (forall a b c.
    (a -> b -> c)
    -> FailToEither a -> FailToEither b -> FailToEither c)
-> (forall a b. FailToEither a -> FailToEither b -> FailToEither b)
-> (forall a b. FailToEither a -> FailToEither b -> FailToEither a)
-> Applicative FailToEither
forall a. a -> FailToEither a
forall a b. FailToEither a -> FailToEither b -> FailToEither a
forall a b. FailToEither a -> FailToEither b -> FailToEither b
forall a b.
FailToEither (a -> b) -> FailToEither a -> FailToEither b
forall a b c.
(a -> b -> c) -> FailToEither a -> FailToEither b -> FailToEither c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> FailToEither a
pure :: forall a. a -> FailToEither a
$c<*> :: forall a b.
FailToEither (a -> b) -> FailToEither a -> FailToEither b
<*> :: forall a b.
FailToEither (a -> b) -> FailToEither a -> FailToEither b
$cliftA2 :: forall a b c.
(a -> b -> c) -> FailToEither a -> FailToEither b -> FailToEither c
liftA2 :: forall a b c.
(a -> b -> c) -> FailToEither a -> FailToEither b -> FailToEither c
$c*> :: forall a b. FailToEither a -> FailToEither b -> FailToEither b
*> :: forall a b. FailToEither a -> FailToEither b -> FailToEither b
$c<* :: forall a b. FailToEither a -> FailToEither b -> FailToEither a
<* :: forall a b. FailToEither a -> FailToEither b -> FailToEither a
Applicative, (forall a b. (a -> b) -> FailToEither a -> FailToEither b)
-> (forall a b. a -> FailToEither b -> FailToEither a)
-> Functor FailToEither
forall a b. a -> FailToEither b -> FailToEither a
forall a b. (a -> b) -> FailToEither a -> FailToEither b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> FailToEither a -> FailToEither b
fmap :: forall a b. (a -> b) -> FailToEither a -> FailToEither b
$c<$ :: forall a b. a -> FailToEither b -> FailToEither a
<$ :: forall a b. a -> FailToEither b -> FailToEither a
Functor, Applicative FailToEither
Applicative FailToEither =>
(forall a b.
 FailToEither a -> (a -> FailToEither b) -> FailToEither b)
-> (forall a b. FailToEither a -> FailToEither b -> FailToEither b)
-> (forall a. a -> FailToEither a)
-> Monad FailToEither
forall a. a -> FailToEither a
forall a b. FailToEither a -> FailToEither b -> FailToEither b
forall a b.
FailToEither a -> (a -> FailToEither b) -> FailToEither b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b.
FailToEither a -> (a -> FailToEither b) -> FailToEither b
>>= :: forall a b.
FailToEither a -> (a -> FailToEither b) -> FailToEither b
$c>> :: forall a b. FailToEither a -> FailToEither b -> FailToEither b
>> :: forall a b. FailToEither a -> FailToEither b -> FailToEither b
$creturn :: forall a. a -> FailToEither a
return :: forall a. a -> FailToEither a
Monad)

instance MonadFail FailToEither where
  fail :: forall a. [Char] -> FailToEither a
fail = Either [Char] a -> FailToEither a
forall a. Either [Char] a -> FailToEither a
FailToEither (Either [Char] a -> FailToEither a)
-> ([Char] -> Either [Char] a) -> [Char] -> FailToEither a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Either [Char] a
forall a b. a -> Either a b
Left
  {-# INLINE fail #-}

-- vim: sw=4 ts=4 expandtab