module Optics.IxAffineFold
(
IxAffineFold
, iafolding
, ipreview
, ipreviews
, iafailing
, An_AffineFold
) where
import Optics.AffineFold
import Optics.Internal.Bi
import Optics.Internal.Indexed
import Optics.Internal.Profunctor
import Optics.Internal.Optic
type IxAffineFold i s a = Optic' An_AffineFold (WithIx i) s a
ipreview
:: (Is k An_AffineFold, is `HasSingleIndex` i)
=> Optic' k is s a
-> s -> Maybe (i, a)
ipreview o = ipreviews o (,)
{-# INLINE ipreview #-}
ipreviews
:: (Is k An_AffineFold, is `HasSingleIndex` i)
=> Optic' k is s a
-> (i -> a -> r) -> s -> Maybe r
ipreviews o = \f -> runIxForgetM
(getOptic (castOptic @An_AffineFold o) . IxForgetM $ \i -> Just . f i)
id
{-# INLINE ipreviews #-}
iafolding :: (s -> Maybe (i, a)) -> IxAffineFold i s a
iafolding g = Optic
$ ivisit (\point f s -> maybe (point s) (uncurry f) $ g s)
. rphantom
{-# INLINE iafolding #-}
iafailing
:: (Is k An_AffineFold, Is l An_AffineFold,
is1 `HasSingleIndex` i, is2 `HasSingleIndex` i)
=> Optic' k is1 s a
-> Optic' l is2 s a
-> IxAffineFold i s a
iafailing a b = conjoined (afailing a b) $ iafolding $ \s ->
maybe (ipreview b s) Just (ipreview a s)
infixl 3 `iafailing`
{-# INLINE iafailing #-}