Browse files

Exposed 'nearly' to end users and gave it haddocks

  • Loading branch information...
1 parent 543a32c commit 02c847864fd8048b487eca9b69e1528c94ecdc87 @ekmett committed Mar 29, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/Control/Lens/Prism.hs
View
10 src/Control/Lens/Prism.hs
@@ -40,6 +40,7 @@ module Control.Lens.Prism
, _Void
, AsEmpty(..)
, only
+ , nearly
-- * Prismatic profunctors
, Choice(..)
) where
@@ -287,6 +288,15 @@ only :: Eq a => a -> Prism' a ()
only a = prism' (\() -> a) $ guard . (a ==)
{-# INLINE only #-}
+
+-- | This 'Prism' compares for approximate equality with a given value and a predicate for testing.
+--
+-- To comply with the 'Prism' laws the arguments you supply to @nearly a p@ are somewhat constrained.
+--
+-- We assume @p x@ holds iff @x ≡ a@. Under that assumption then this is a valid 'Prism'.
+--
+-- This is useful when working with a type where you can test equality for only a subset of its
+-- values, and the prism selects such a value.
nearly :: a -> (a -> Bool) -> Prism' a ()
nearly a p = prism' (\() -> a) $ guard . p
{-# INLINE nearly #-}

0 comments on commit 02c8478

Please sign in to comment.