softwaremill / softwaremill/quicklens

eachWhere for maps

Open
#52 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
852
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Currently it appears impossible to use eachWhere with a map. It is formally possible to invoke eachWhere on a Map[A, B], but it would result in this method using Iterable[(A, B)] as the output for setting the value, which causes type mismatch errors.

My use case is as follows. I have a map like Map[String, SomeValue] and I need to modify only those entries whose key satisfies some predicate:

val predicate: ((String, SomeValue)) => Boolean = {
  case (k, _) => someConditionOnKey(k)
}
modify(_.sources.eachWhere(predicate).nested.value)

Apparently there is no simple way to do it now. Having an ability to use eachWhere on a map would solve the issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the eachWhere implementation and any tests covering collection updates; the issue provides no file or test names. Reproduce the shown Map[String, SomeValue] case, then define done as allowing eachWhere to update only matching map entries without the reported type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.