module Optics.IxGetter
(
IxGetter
, ito
, selfIndex
, iview
, iviews
, A_Getter
) where
import Optics.Internal.Bi
import Optics.Internal.Indexed
import Optics.Internal.Optic
import Optics.Internal.Profunctor
type IxGetter i s a = Optic' A_Getter (WithIx i) s a
ito :: (s -> (i, a)) -> IxGetter i s a
ito f = Optic (lmap f . ilinear uncurry . rphantom)
{-# INLINE ito #-}
selfIndex :: IxGetter a a a
selfIndex = ito (\a -> (a, a))
{-# INLINE selfIndex #-}
iview
:: (Is k A_Getter, is `HasSingleIndex` i)
=> Optic' k is s a -> s -> (i, a)
iview o = iviews o (,)
{-# INLINE iview #-}
iviews
:: (Is k A_Getter, is `HasSingleIndex` i)
=> Optic' k is s a -> (i -> a -> r) -> s -> r
iviews o = \f ->
runIxForget (getOptic (castOptic @A_Getter o) (IxForget f)) id
{-# INLINE iviews #-}