module Fold.ShortcutNonempty.Utilities where

import Fold.ShortcutNonempty.Type

import Strict (willSave)

import qualified Strict

{-| Causes a shortcut fold to stop once it becomes ambivalent -}
demotivate :: ShortcutNonemptyFold a b -> ShortcutNonemptyFold a b
demotivate :: forall a b. ShortcutNonemptyFold a b -> ShortcutNonemptyFold a b
demotivate ShortcutNonemptyFold{ a -> Vitality x y
initial :: ()
initial :: a -> Vitality x y
initial, y -> a -> Vitality x y
step :: ()
step :: y -> a -> Vitality x y
step, x -> b
extractDead :: ()
extractDead :: x -> b
extractDead, y -> b
extractLive :: ()
extractLive :: y -> b
extractLive } =
  ShortcutNonemptyFold
    { initial :: a -> Vitality (Either x y) y
initial = \a
a -> forall a b. Vitality a b -> Vitality (Either a b) b
willSave (a -> Vitality x y
initial a
a)
    , step :: y -> a -> Vitality (Either x y) y
step = \y
x a
a -> forall a b. Vitality a b -> Vitality (Either a b) b
willSave (y -> a -> Vitality x y
step y
x a
a)
    , extractDead :: Either x y -> b
extractDead = \Either x y
e -> case Either x y
e of
          Strict.Left x
x -> x -> b
extractDead x
x
          Strict.Right y
x -> y -> b
extractLive y
x
    , extractLive :: y -> b
extractLive = y -> b
extractLive
    }