Skip to content
This repository
Browse code

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

  • Loading branch information...
commit a61a679a03a5127ac4d583bb29a5b74958a03e8d 1 parent 52db230
Edward Kmett authored October 26, 2012
4  CHANGELOG.markdown
Source Rendered
... ...
@@ -1,3 +1,7 @@
  1
+3.0.5
  2
+-----
  3
+* Fixed a bug in `rights1` and `lefts1` in `Control.Lens.Zipper` which would cause them to loop forever when given a 0 offset.
  4
+
1 5
 3.0.4
2 6
 -----
3 7
 * 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`.
2  lens.cabal
... ...
@@ -1,6 +1,6 @@
1 1
 name:          lens
2 2
 category:      Data, Lenses
3  
-version:       3.0.4
  3
+version:       3.0.5
4 4
 license:       BSD3
5 5
 cabal-version: >= 1.8
6 6
 license-file:  LICENSE
4  src/Control/Lens/Zipper.hs
@@ -190,7 +190,7 @@ lefts k z
190 190
 -- Passing a negative @n@ will move to @-n@ entries the right, and will return the last entry if you run out of entries.
191 191
 lefts1 :: Int -> (h :> a) -> h :> a
192 192
 lefts1 n z
193  
-  | n <= 0 = rights1 (-n) z
  193
+  | n < 0 = rights1 (-n) z
194 194
   | otherwise = go n z
195 195
   where go 0 c = c
196 196
         go k c = case left c of
@@ -202,7 +202,7 @@ lefts1 n z
202 202
 -- Passing a negative number will move to the left and will return the first entry if you run out of entries.
203 203
 rights1 :: Int -> (h :> a) -> h :> a
204 204
 rights1 n z
205  
-  | n <= 0 = lefts1 (-n) z
  205
+  | n < 0 = lefts1 (-n) z
206 206
   | otherwise = go n z
207 207
   where go 0 c = c
208 208
         go k c = case right c of

1 note on commit a61a679

Edward Kmett
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.