-- | Folds of other types trivially lifted into 'Fold'
module Fold.Pure.Examples.Boring
  (
    {- * Length -} null,
    {- * General -} magma, semigroup,
    {- * Endpoints -} first, last,
    {- * Extrema -} maximum, minimum, maximumBy, minimumBy,
    {- * Boolean -} and, or, all, any,
    {- * Search -} element, notElement, find, lookup,
    {- * Index -} index, findIndex, elementIndex,
  )
  where

import Data.Maybe (Maybe)
import Data.Ord (Ord, Ordering)
import Data.Semigroup (Semigroup)
import Fold.Pure.Type (Fold)
import Data.Bool (Bool)
import Data.Eq (Eq)
import Numeric.Natural (Natural)

import qualified Fold.Pure.Conversion as Convert
import qualified Fold.Nonempty.Examples.Interesting as Nonempty
import qualified Fold.ShortcutNonempty.Examples.Interesting as ShortcutNonempty
import qualified Fold.Shortcut.Examples.Interesting as Shortcut

{-| 'True' if the input contains no inputs -}
null :: Fold a Bool
null :: forall a. Fold a Bool
null = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold forall a. ShortcutFold a Bool
Shortcut.null

{-| Start with the first input, append each new input on the right
with the given function -}
magma :: (a -> a -> a) -> Fold a (Maybe a)
magma :: forall a. (a -> a -> a) -> Fold a (Maybe a)
magma a -> a -> a
step = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold (forall a. (a -> a -> a) -> NonemptyFold a a
Nonempty.magma a -> a -> a
step)

{-| Append each new input on the right with ('<>') -}
semigroup :: Semigroup a => Fold a (Maybe a)
semigroup :: forall a. Semigroup a => Fold a (Maybe a)
semigroup = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold forall a. Semigroup a => NonemptyFold a a
Nonempty.semigroup

{-| The first input -}
first :: Fold a (Maybe a)
first :: forall a. Fold a (Maybe a)
first = forall a b. ShortcutNonemptyFold a b -> Fold a (Maybe b)
Convert.shortcutNonemptyFold forall a. ShortcutNonemptyFold a a
ShortcutNonempty.first

{-| The last input -}
last :: Fold a (Maybe a)
last :: forall a. Fold a (Maybe a)
last = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold forall a. NonemptyFold a a
Nonempty.last

{-| The greatest input -}
maximum :: Ord a => Fold a (Maybe a)
maximum :: forall a. Ord a => Fold a (Maybe a)
maximum = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold forall a. Ord a => NonemptyFold a a
Nonempty.maximum

{-| The greatest input with respect to the given comparison function -}
maximumBy :: (a -> a -> Ordering) -> Fold a (Maybe a)
maximumBy :: forall a. (a -> a -> Ordering) -> Fold a (Maybe a)
maximumBy a -> a -> Ordering
cmp = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold (forall a. (a -> a -> Ordering) -> NonemptyFold a a
Nonempty.maximumBy a -> a -> Ordering
cmp)

{-| The least input -}
minimum :: Ord a => Fold a (Maybe a)
minimum :: forall a. Ord a => Fold a (Maybe a)
minimum = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold forall a. Ord a => NonemptyFold a a
Nonempty.minimum

{-| The least input with respect to the given comparison function -}
minimumBy :: (a -> a -> Ordering) -> Fold a (Maybe a)
minimumBy :: forall a. (a -> a -> Ordering) -> Fold a (Maybe a)
minimumBy a -> a -> Ordering
cmp = forall a b. NonemptyFold a b -> Fold a (Maybe b)
Convert.nonemptyFold (forall a. (a -> a -> Ordering) -> NonemptyFold a a
Nonempty.minimumBy a -> a -> Ordering
cmp)

{-| 'True' if all inputs are 'True' -}
and :: Fold Bool Bool
and :: Fold Bool Bool
and = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold ShortcutFold Bool Bool
Shortcut.and

{-| 'True' if any input is 'True' -}
or :: Fold Bool Bool
or :: Fold Bool Bool
or = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold ShortcutFold Bool Bool
Shortcut.or

{-| 'True' if all inputs satisfy the predicate -}
all :: (a -> Bool) -> Fold a Bool
all :: forall a. (a -> Bool) -> Fold a Bool
all a -> Bool
predicate = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. (a -> Bool) -> ShortcutFold a Bool
Shortcut.all a -> Bool
predicate)

{-| 'True' if any input satisfies the predicate -}
any :: (a -> Bool) -> Fold a Bool
any :: forall a. (a -> Bool) -> Fold a Bool
any a -> Bool
predicate = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. (a -> Bool) -> ShortcutFold a Bool
Shortcut.any a -> Bool
predicate)

{-| 'True' if any input is equal to the given value -}
element :: Eq a => a -> Fold a Bool
element :: forall a. Eq a => a -> Fold a Bool
element a
a = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. Eq a => a -> ShortcutFold a Bool
Shortcut.element a
a)

{-| 'False' if any input is equal to the given value -}
notElement :: Eq a => a -> Fold a Bool
notElement :: forall a. Eq a => a -> Fold a Bool
notElement a
a = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. Eq a => a -> ShortcutFold a Bool
Shortcut.notElement a
a)

{-| The first input that satisfies the predicate, if any -}
find :: (a -> Bool) -> Fold a (Maybe a)
find :: forall a. (a -> Bool) -> Fold a (Maybe a)
find a -> Bool
ok = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. (a -> Bool) -> ShortcutFold a (Maybe a)
Shortcut.find a -> Bool
ok)

{-| The /n/th input, where n=0 is the first input, if the index is in bounds -}
index :: Natural -> Fold a (Maybe a)
index :: forall a. Natural -> Fold a (Maybe a)
index Natural
i = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. Natural -> ShortcutFold a (Maybe a)
Shortcut.index Natural
i)

{-| The index of the first input that matches the given value, if any -}
elementIndex :: Eq a => a -> Fold a (Maybe Natural)
elementIndex :: forall a. Eq a => a -> Fold a (Maybe Natural)
elementIndex a
a = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. Eq a => a -> ShortcutFold a (Maybe Natural)
Shortcut.elementIndex a
a)

{-| The index of the first input that satisfies the predicate, if any -}
findIndex :: (a -> Bool) -> Fold a (Maybe Natural)
findIndex :: forall a. (a -> Bool) -> Fold a (Maybe Natural)
findIndex a -> Bool
ok = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a. (a -> Bool) -> ShortcutFold a (Maybe Natural)
Shortcut.findIndex a -> Bool
ok)

{-| The @b@ from the first tuple where @a@ equals the given value, if any -}
lookup :: Eq a => a -> Fold (a, b) (Maybe b)
lookup :: forall a b. Eq a => a -> Fold (a, b) (Maybe b)
lookup a
a0 = forall a b. ShortcutFold a b -> Fold a b
Convert.shortcutFold (forall a b. Eq a => a -> ShortcutFold (a, b) (Maybe b)
Shortcut.lookup a
a0)