Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed infinite loop on `lefts1 0` or `rights1 0`.

  • Loading branch information...
commit a61a679a03a5127ac4d583bb29a5b74958a03e8d 1 parent 52db230
@ekmett authored
Showing with 7 additions and 3 deletions.
  1. +4 −0 CHANGELOG.markdown
  2. +1 −1  lens.cabal
  3. +2 −2 src/Control/Lens/Zipper.hs
View
4 CHANGELOG.markdown
@@ -1,3 +1,7 @@
+3.0.5
+-----
+* Fixed a bug in `rights1` and `lefts1` in `Control.Lens.Zipper` which would cause them to loop forever when given a 0 offset.
+
3.0.4
-----
* Added `?~`, `<?~`, `?=` and `<?=` to `Control.Lens.Setter` for setting the target(s) of a Lens to `Just` a value. They are particularly useful when combined with `at`.
View
2  lens.cabal
@@ -1,6 +1,6 @@
name: lens
category: Data, Lenses
-version: 3.0.4
+version: 3.0.5
license: BSD3
cabal-version: >= 1.8
license-file: LICENSE
View
4 src/Control/Lens/Zipper.hs
@@ -190,7 +190,7 @@ lefts k z
-- Passing a negative @n@ will move to @-n@ entries the right, and will return the last entry if you run out of entries.
lefts1 :: Int -> (h :> a) -> h :> a
lefts1 n z
- | n <= 0 = rights1 (-n) z
+ | n < 0 = rights1 (-n) z
| otherwise = go n z
where go 0 c = c
go k c = case left c of
@@ -202,7 +202,7 @@ lefts1 n z
-- Passing a negative number will move to the left and will return the first entry if you run out of entries.
rights1 :: Int -> (h :> a) -> h :> a
rights1 n z
- | n <= 0 = lefts1 (-n) z
+ | n < 0 = lefts1 (-n) z
| otherwise = go n z
where go 0 c = c
go k c = case right c of

1 comment on commit a61a679

@ekmett
Owner

This patch is the result of the awesome contributions of @shachaf. Noting it here for posterity.

Please sign in to comment.
Something went wrong with that request. Please try again.