{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Optics.Indexed
(
IxOptic(..)
, conjoined
, (<%>)
, (%>)
, (<%)
, reindexed
, icompose
, icompose3
, icompose4
, icompose5
, icomposeN
, module Optics.IxAffineFold
, module Optics.IxAffineTraversal
, module Optics.IxFold
, module Optics.IxGetter
, module Optics.IxLens
, module Optics.IxSetter
, module Optics.IxTraversal
, FunctorWithIndex (..)
, FoldableWithIndex (..)
, itraverse_
, ifor_
, itoList
, TraversableWithIndex (..)
, ifor
) where
import qualified Data.HashMap.Lazy as HM
import qualified Data.Vector as V
import Optics.Indexed.Core
import Optics.IxAffineFold
import Optics.IxAffineTraversal
import Optics.IxFold
import Optics.IxGetter
import Optics.IxLens
import Optics.IxSetter
import Optics.IxTraversal
instance FunctorWithIndex k (HM.HashMap k) where
imap = HM.mapWithKey
{-# INLINE imap #-}
instance FoldableWithIndex k (HM.HashMap k) where
ifoldr = HM.foldrWithKey
ifoldl' = HM.foldlWithKey' . flip
{-# INLINE ifoldr #-}
{-# INLINE ifoldl' #-}
instance TraversableWithIndex k (HM.HashMap k) where
itraverse = HM.traverseWithKey
{-# INLINE itraverse #-}
instance FunctorWithIndex Int V.Vector where
imap = V.imap
{-# INLINE imap #-}
instance FoldableWithIndex Int V.Vector where
ifoldMap f = ifoldr (\i -> mappend . f i) mempty
ifoldr = V.ifoldr
ifoldl' = V.ifoldl' . flip
{-# INLINE ifoldMap #-}
{-# INLINE ifoldr #-}
{-# INLINE ifoldl' #-}
instance TraversableWithIndex Int V.Vector where
itraverse f v =
let !n = V.length v in V.fromListN n <$> itraverse f (V.toList v)
{-# INLINE itraverse #-}