@@ -122,24 +122,35 @@ withSemiIso :: ASemiIso s t a b
122122withSemiIso ai k = case ai (Retail Right (Right . Identity)) of
123123 Retail sa bt -> k sa (rmap (runIdentity . sequenceA) bt)
124124
125+-- | Transforms the semi-iso so that applying it in both directions never fails,
126+-- but instead catches any errors and returns them as an @Either String a@.
125127attempt :: ASemiIso s t a b -> SemiIso s (Either String t) (Either String a) b
126128attempt = attemptAp . attemptUn
127129
130+-- | Transforms the semi-iso so that applying it in direction (->) never fails,
131+-- but instead catches any errors and returns them as an @Either String a@.
128132attemptAp :: ASemiIso s t a b -> SemiIso s t (Either String a) b
129−attemptAp = undefined
133+attemptAp ai = withSemiIso ai $ \l r -> semiIso (Right . l) r
130134
135+-- | Transforms the semi-iso so that applying it in direction (<-) never fails,
136+-- but instead catches any errors and returns them as an @Either String a@.
131137attemptUn :: ASemiIso s t a b -> SemiIso s (Either String t) a b
132−attemptUn = undefined
138+attemptUn ai = withSemiIso ai $ \l r -> semiIso l (Right . r)
133139
134140discard :: Either a b -> Maybe b
135141discard = either (const Nothing) Just
136142
143+-- | Transforms the semi-iso like 'attempt', but ignores the error message.
137144attempt_ :: ASemiIso s t a b -> SemiIso s (Maybe t) (Maybe a) b
138145attempt_ ai = rmap (fmap discard) . attempt ai . lmap discard
139146
147+-- | Transforms the semi-iso like 'attemptAp', but ignores the error message.
148+--
149+-- Very useful when you want to bifold using a prism.
140150attemptAp_ :: ASemiIso s t a b -> SemiIso s t (Maybe a) b
141151attemptAp_ ai = attemptAp ai . lmap discard
142152
153+-- | Transforms the semi-iso like 'attemptUn', but ignores the error message.
143154attemptUn_ :: ASemiIso s t a b -> SemiIso s (Maybe t) a b
144155attemptUn_ ai = rmap (fmap discard) . attemptUn ai
145156