Skip to content

Conversation

@jfmengels
Copy link
Owner

@jfmengels jfmengels commented Dec 26, 2025

Adds this check from #2 (which we should at this point close and re-open in separate issues to make it easier to close them).

List.foldl f initial (List.reverse list)
--> List.foldr f initial list

List.foldr f initial (List.reverse list)
--> List.foldl f initial list

and composition

Copy link
Collaborator

@lue-bird lue-bird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suuper nice!

src/Simplify.elm Outdated
, actionRepresents = "reverse it"
, combinedFn =
( [ "List" ]
, if foldFnName == "foldl" then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would probably pass this as a parameter "reverseFoldFnName" or similar but it's alright as is

@lue-bird
Copy link
Collaborator

lue-bird commented Dec 26, 2025

Also: Not really necessary but if you want, add these to the correctness tests:

, Test.fuzz
  (Fuzz.list Fuzz.string)
  "List.reverse >> List.foldl is the same as List.foldr"
  (\list ->
      list
          |> List.reverse
          |> List.foldl (::) []
          |> Expect.equalLists
              (list
                  |> List.foldr (::) []
              )
  )
, Test.fuzz
  (Fuzz.list Fuzz.string)
  "List.reverse >> List.foldr is the same as List.foldl"
  (\list ->
      list
          |> List.reverse
          |> List.foldr (::) []
          |> Expect.equalLists
              (list
                  |> List.foldl (::) []
              )
  )

@jfmengels jfmengels merged commit 4023592 into main Dec 26, 2025
2 checks passed
@jfmengels jfmengels deleted the list-fold-reverse branch December 26, 2025 10:50
@jfmengels
Copy link
Owner Author

Merged with your suggestions 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants