@@ -79,19 +79,16 @@ module Control.Lens.SemiIso (
79 attemptAp_,
79 attemptAp_,
80 attemptUn_,
80 attemptUn_,
90 -- * Bidirectional folds.
82 -- * Bidirectional folds.
94− bifoldl1
86+ bifoldl1,
97import Control.Arrow
94import Control.Arrow
@@ -300,13 +297,47 @@ unfoldlM1 f a0 = go a0 []
300 Just (new_a, b) -> go new_a (b : bs)
297 Just (new_a, b) -> go new_a (b : bs)
301 Nothing -> return (a : bs)
298 Nothing -> return (a : bs)
300+-- | Constructs a bidirectional fold.
302+-- \-> Right unfolds using the (->) part of the given semi-iso, until it fails.
304+-- \<- Right folds using the (<-) part of the given semi-iso.
305+bifoldr :: ASemiIso' a (b, a) -> SemiIso' a (a, [b])
306+bifoldr = bifoldr_ . attemptAp_
308+-- | Constructs a bidirectional fold.
310+-- \-> Right unfolds using the (->) part of the given semi-iso, until it fails.
311+-- It should produce a non-empty list.
313+-- \<- Right folds a non-empty list using the (<-) part of the given semi-iso.
314+bifoldr1 :: ASemiIso' a (a, a) -> SemiIso' a [a]
315+bifoldr1 = bifoldr1_ . attemptAp_
317+-- | Constructs a bidirectional fold.
319+-- \-> Left unfolds using the (->) part of the given semi-iso, until it fails.
321+-- \<- Left folds using the (<-) part of the given semi-iso.
322+bifoldl :: ASemiIso' a (a, b) -> SemiIso' a (a, [b])
323+bifoldl = bifoldl_ . attemptAp_
325+-- | Constructs a bidirectional fold.
327+-- \-> Left unfolds using the (->) part of the given semi-iso, until it fails.
328+-- It should produce a non-empty list.
330+-- \<- Left folds a non-empty list using the (<-) part of the given semi-iso.
331+bifoldl1 :: ASemiIso' a (a, a) -> SemiIso' a [a]
332+bifoldl1 = bifoldl1_ . attemptAp_
303-- | Constructs a bidirectional fold.
334-- | Constructs a bidirectional fold.
305-- \-> Right unfolds using the (->) part of the given semi-iso.
336-- \-> Right unfolds using the (->) part of the given semi-iso.
307-- \<- Right folds using the (<-) part of the given semi-iso.
338-- \<- Right folds using the (<-) part of the given semi-iso.
308−bifoldr :: ASemiIso a a (Maybe (b, a)) (b, a) -> SemiIso' a (a, [b])
339+bifoldr_ :: ASemiIso a a (Maybe (b, a)) (b, a) -> SemiIso' a (a, [b])
309−bifoldr ai = semiIso (uf ai) (f ai)
340+bifoldr_ ai = semiIso (uf ai) (f ai)
311 f = uncurry . foldrM . curry . unapply
342 f = uncurry . foldrM . curry . unapply
312 uf = unfoldrM . apply
343 uf = unfoldrM . apply
@@ -314,11 +345,11 @@ bifoldr ai = semiIso (uf ai) (f ai)
314-- | Constructs a bidirectional fold.
345-- | Constructs a bidirectional fold.
316-- \-> Right unfolds using the (->) part of the given semi-iso. It should
347-- \-> Right unfolds using the (->) part of the given semi-iso. It should
317−-- produce an non-empty list.
348+-- produce a non-empty list.
319-- \<- Right folds a non-empty list using the (<-) part of the given semi-iso.
350-- \<- Right folds a non-empty list using the (<-) part of the given semi-iso.
320−bifoldr1 :: ASemiIso a a (Maybe (a, a)) (a, a) -> SemiIso' a [a]
351+bifoldr1_ :: ASemiIso a a (Maybe (a, a)) (a, a) -> SemiIso' a [a]
321−bifoldr1 ai = semiIso (uf ai) (f ai)
352+bifoldr1_ ai = semiIso (uf ai) (f ai)
323 f = foldrM1 . curry . unapply
354 f = foldrM1 . curry . unapply
324 uf = unfoldrM1 . apply
355 uf = unfoldrM1 . apply
@@ -328,8 +359,8 @@ bifoldr1 ai = semiIso (uf ai) (f ai)
328-- \-> Left unfolds using the (->) part of the given semi-iso.
359-- \-> Left unfolds using the (->) part of the given semi-iso.
330-- \<- Left folds using the (<-) part of the given semi-iso.
361-- \<- Left folds using the (<-) part of the given semi-iso.
331−bifoldl :: ASemiIso a a (Maybe (a, b)) (a, b) -> SemiIso' a (a, [b])
362+bifoldl_ :: ASemiIso a a (Maybe (a, b)) (a, b) -> SemiIso' a (a, [b])
332−bifoldl ai = semiIso (uf ai) (f ai)
363+bifoldl_ ai = semiIso (uf ai) (f ai)
334 f = uncurry . foldlM . curry . unapply
365 f = uncurry . foldlM . curry . unapply
335 uf = unfoldlM . apply
366 uf = unfoldlM . apply
@@ -337,11 +368,11 @@ bifoldl ai = semiIso (uf ai) (f ai)
337-- | Constructs a bidirectional fold.
368-- | Constructs a bidirectional fold.
339-- \-> Left unfolds using the (->) part of the given semi-iso. It should
370-- \-> Left unfolds using the (->) part of the given semi-iso. It should
340−-- produce an non-empty list.
371+-- produce a non-empty list.
342-- \<- Left folds a non-empty list using the (<-) part of the given semi-iso.
373-- \<- Left folds a non-empty list using the (<-) part of the given semi-iso.
343−bifoldl1 :: ASemiIso a a (Maybe (a, a)) (a, a) -> SemiIso' a [a]
374+bifoldl1_ :: ASemiIso a a (Maybe (a, a)) (a, a) -> SemiIso' a [a]
344−bifoldl1 ai = semiIso (uf ai) (f ai)
375+bifoldl1_ ai = semiIso (uf ai) (f ai)
346 f = foldlM1 . curry . unapply
377 f = foldlM1 . curry . unapply
347 uf = unfoldlM1 . apply
378 uf = unfoldlM1 . apply