Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion review/suppressed/NoUnoptimizedRecursion.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"automatically created by": "elm-review suppress",
"learn more": "elm-review suppress --help",
"suppressions": [
{ "count": 9, "filePath": "src/List/Extra.elm" }
{ "count": 5, "filePath": "src/List/Extra.elm" }
]
}
82 changes: 42 additions & 40 deletions src/List/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1232,12 +1232,17 @@ In this example, everybody shakes hands with three other people.
-}
uniquePairs : List a -> List ( a, a )
uniquePairs xs =
case xs of
[] ->
[]
let
go : List a -> List ( a, a ) -> List ( a, a )
go queue acc =
case queue of
[] ->
List.reverse acc

x :: xs_ ->
List.map (\y -> ( x, y )) xs_ ++ uniquePairs xs_
h :: t ->
go t (List.foldl (\o a -> ( h, o ) :: a) acc t)
in
go xs []


reverseAppend : List a -> List a -> List a
Expand Down Expand Up @@ -1355,17 +1360,13 @@ stoppableFoldl func acc list =
scanl : (a -> b -> b) -> b -> List a -> List b
scanl f b xs =
let
scan1 x accAcc =
case accAcc of
acc :: _ ->
f x acc :: accAcc

[] ->
[]
scan1 x ( accHead, accTail ) =
( f x accHead, accHead :: accTail )

-- impossible
( h, t ) =
List.foldl scan1 ( b, [] ) xs
in
List.reverse (List.foldl scan1 [ b ] xs)
List.reverse (h :: t)


{-| `scanl1` is a variant of `scanl` that has no starting value argument.
Expand Down Expand Up @@ -1409,18 +1410,15 @@ Examples:

-}
scanr : (a -> b -> b) -> b -> List a -> List b
scanr f acc xs_ =
case xs_ of
[] ->
[ acc ]

x :: xs ->
case scanr f acc xs of
(q :: _) as qs ->
f x q :: qs
scanr f b xs_ =
let
scan1 x ( accHead, accTail ) =
( f x accHead, accHead :: accTail )

[] ->
[]
( h, t ) =
List.foldr scan1 ( b, [] ) xs_
in
h :: t


{-| `scanr1` is a variant of `scanr` that has no starting value argument.
Expand All @@ -1434,20 +1432,19 @@ scanr f acc xs_ =
-}
scanr1 : (a -> a -> a) -> List a -> List a
scanr1 f xs_ =
case xs_ of
case List.reverse xs_ of
[] ->
[]

[ x ] ->
[ x ]

x :: xs ->
case scanr1 f xs of
(q :: _) as qs ->
f x q :: qs
b :: xs ->
let
scan1 x ( accHead, accTail ) =
( f x accHead, accHead :: accTail )

[] ->
[]
( h, t ) =
List.foldl scan1 ( b, [] ) xs
in
h :: t


{-| The mapAccuml function behaves like a combination of map and foldl; it applies a
Expand Down Expand Up @@ -1543,12 +1540,17 @@ mapAccumr f acc0 list =
-}
unfoldr : (b -> Maybe ( a, b )) -> b -> List a
unfoldr f seed =
case f seed of
Nothing ->
[]
let
go : b -> List a -> List a
go x acc =
case f x of
Nothing ->
List.reverse acc

Just ( a, b ) ->
a :: unfoldr f b
Just ( a, b ) ->
go b (a :: acc)
in
go seed []


{-| Take a number and a list, return a tuple of lists, where first part is prefix of the list of length equal the number, and second part is the remainder of the list. `splitAt n xs` is equivalent to `(take n xs, drop n xs)`.
Expand Down
Loading