nonEmptyTraverse for NEM with key mapping#4759
Open
dpevunov-cp wants to merge 1 commit intotypelevel:mainfrom
Open
nonEmptyTraverse for NEM with key mapping#4759dpevunov-cp wants to merge 1 commit intotypelevel:mainfrom
dpevunov-cp wants to merge 1 commit intotypelevel:mainfrom
Conversation
Contributor
|
Hi @dpevunov-cp , thank you for the PR! I think I understand what you're trying to achieve, but I've got a couple of suggestions about the proposed method:
|
johnynek
reviewed
Jul 15, 2025
| if (t.isEmpty) | ||
| Eval.now(G.map(f.tupled(h))(b => NonEmptyMap(b, SortedMap.empty[L, B](ordL.toOrdering)))) | ||
| else | ||
| G.map2Eval(f.tupled(h), Eval.defer(loop(t.head, t.tail)))((lb, acc) => NonEmptyMap(lb, acc.toSortedMap)) |
Contributor
There was a problem hiding this comment.
Why wrap and unwrap with NonEmptyMap on every step? Why not do it once at the end after calling .value?
| loop(head, tail).value | ||
| } | ||
|
|
||
| def nonEmptyTraverse[G[_], L, B]( |
Contributor
There was a problem hiding this comment.
I think this name isn't right. Traverse on maps only uses the values, not the keys. So if you are going to use the keys I think we need a new name. Something like nonEmptyTraversePairs or traverseWithKey or something.
Contributor
There was a problem hiding this comment.
NonEmptyMap already has map (values only) and mapBoth (keys with values). So I guess this should be nonEmptyTraverseBoth then.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.