Skip to content

Commit ab4b5e4

Browse files
committed
Make uniquePairs TCO
1 parent d4464e1 commit ab4b5e4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

review/suppressed/NoUnoptimizedRecursion.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"automatically created by": "elm-review suppress",
44
"learn more": "elm-review suppress --help",
55
"suppressions": [
6-
{ "count": 6, "filePath": "src/List/Extra.elm" }
6+
{ "count": 5, "filePath": "src/List/Extra.elm" }
77
]
88
}

src/List/Extra.elm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,12 +1232,17 @@ In this example, everybody shakes hands with three other people.
12321232
-}
12331233
uniquePairs : List a -> List ( a, a )
12341234
uniquePairs xs =
1235-
case xs of
1236-
[] ->
1237-
[]
1235+
let
1236+
go : List a -> List ( a, a ) -> List ( a, a )
1237+
go queue acc =
1238+
case queue of
1239+
[] ->
1240+
List.reverse acc
12381241

1239-
x :: xs_ ->
1240-
List.map (\y -> ( x, y )) xs_ ++ uniquePairs xs_
1242+
h :: t ->
1243+
go t (List.foldl (\o a -> ( h, o ) :: a) acc t)
1244+
in
1245+
go xs []
12411246

12421247

12431248
reverseAppend : List a -> List a -> List a

0 commit comments

Comments
 (0)