{-| Monomorphic lenses where the getters and updates can potentially silently
fail. Partial lenses are useful for creating accessor labels for multi
constructor data types where projection and modification of fields will not
always succeed.
-}{-# LANGUAGE TypeOperators #-}moduleData.Label.Partial((:~>),Partial,lens,get,modify,set,embed-- * Seemingly total modifications.,set',modify'-- * Potentially removing modification.,update)whereimportControl.ApplicativeimportControl.ArrowimportControl.CategoryimportData.Label.Point(Partial)importData.Label.Poly(Lens)importData.MaybeimportPreludehiding((.),id)importqualifiedData.Label.PolyasPoly{-# INLINE lens #-}{-# INLINE get #-}{-# INLINE modify #-}{-# INLINE set #-}{-# INLINE embed #-}{-# INLINE set' #-}{-# INLINE modify' #-}-- | Partial lens type for situations in which the accessor functions can fail.typef:~>o=LensPartialfo--------------------------------------------------------------------------------- | Create a lens that can fail from a getter and a modifier that can-- themselves potentially fail.lens::(f->Maybeo)-- ^ Getter.->((o->Maybei)->f->Maybeg)-- ^ Modifier.->(f->g):~>(o->i)lensgs=Poly.lens(Kleislig)(Kleisli(\(m,f)->s(runKleislim)f))-- | Getter for a lens that can fail. When the field to which the lens points-- is not accessible the getter returns 'Nothing'.get::(f->g):~>(o->i)->f->Maybeogetl=runKleisli(Poly.getl)-- | Modifier for a lens that can fail. When the field to which the lens points-- is not accessible this function returns 'Nothing'.modify::(f->g):~>(o->i)->(o->i)->f->Maybegmodifylm=runKleisli(Poly.modifyl.arr((,)(arrm)))-- | Setter for a lens that can fail. When the field to which the lens points-- is not accessible this function returns 'Nothing'.set::(f->g):~>(o->i)->i->f->Maybegsetlv=runKleisli(Poly.setl.arr((,)v))-- | Embed a total lens that points to a `Maybe` field into a lens that might-- fail.embed::Lens(->)(f->g)(Maybeo->Maybei)->(f->g):~>(o->i)embedl=lens(Poly.getl)(\mf->const(Poly.modifyl((>>=m),f))<$>Poly.getlf)--------------------------------------------------------------------------------- | Like 'modify' but return behaves like the identity function when the field-- could not be set.modify'::(f->f):~>(o->o)->(o->o)->f->fmodify'lmf=f`fromMaybe`modifylmf-- | Like 'set' but return behaves like the identity function when the field-- could not be set.set'::(f->f):~>(o->o)->o->f->fset'lvf=f`fromMaybe`setlvf-- | Like `modify`, but update allows, depending on the underlying lens, to-- remove items by modifying to `Nothing`.update::(f->b):~>(o->i)->(o->Maybei)->f->Maybebupdatelm=runKleisli(Poly.modifyl.arr((,)(Kleislim)))