Merge pull request #185 from actionshrimp/cclist-repeat-reversed

Don't reverse twice in `CCList.repeat`
This commit is contained in:
Simon Cruanes 2018-02-04 11:57:05 -06:00 committed by GitHub
commit 9e51f8dc77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -25,3 +25,4 @@
- Fabian Hemmer (copy) - Fabian Hemmer (copy)
- Maciej Woś (@lostman) - Maciej Woś (@lostman)
- Orbifx (Stavros Polymenis) - Orbifx (Stavros Polymenis)
- Dave Aitken (@actionshrimp)

View file

@ -1253,11 +1253,15 @@ let replicate i x =
else aux (x::acc) (i-1) else aux (x::acc) (i-1)
in aux [] i in aux [] i
(*$T
repeat 2 [1;2;3] = [1;2;3;1;2;3]
*)
let repeat i l = let repeat i l =
let l' = List.rev l in
let rec aux acc i = let rec aux acc i =
if i = 0 then List.rev acc if i = 0 then List.rev acc
else aux (List.rev_append l' acc) (i-1) else aux (List.rev_append l acc) (i-1)
in aux [] i in aux [] i
module Assoc = struct module Assoc = struct