Skip to content

Conversation

@johnynek
Copy link
Contributor

This adds that unorderedTraverse should be consistent with unorderedFoldMap, which seems intuitively obvious, but isn't checked.

Adding this law passes for both the current implementations of UnorderedTraverse (a typeclass I think very rarely used). However, note I just created: #4802 which argues that UnorderedTraverse[Set] should be deprecated because it should be unlawful (although with the current laws it is not).

Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

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

lgtm!

@johnynek johnynek merged commit f92ec27 into main Dec 23, 2025
33 checks passed
@LukaJCB LukaJCB deleted the oscar/20251220-add_unordered_traverse_law branch December 23, 2025 01:29
@satorg
Copy link
Contributor

satorg commented Dec 25, 2025

@johnynek ,
Is there any reason why we cannot say the same about regular traverse/foldMap?
I personally couldn't think of any, but perhaps I'm missing something.
I tried to add this law to TraverseLaws:

def traverseConsistentFoldMap[A, B: Monoid](fa: F[A], fn: A => B): IsEq[B] =
  F.traverse(fa)(a => Const[B, B](fn(a))).getConst <-> F.foldMap(fa)(fn)

and the tests seem passing.

I can file a PR from that excersice if you believe it makes sense.

@johnynek
Copy link
Contributor Author

Honestly I just assumed that law was already there. I think this should definitely be a law but I wonder if you could prove it from any other laws that exist. I think we should add it.

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.

4 participants