quicklens icon indicating copy to clipboard operation
quicklens copied to clipboard

eachWhere for maps

Open netvl opened this issue 5 years ago • 0 comments

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.

netvl avatar May 25 '19 01:05 netvl