softwaremill / softwaremill/quicklens
Setting nested Options to Some(value)
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 852
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
Given a nested chain of Options, is there a way to coerce the most inner one to Some?
The current operator .each allows traversing Options, but acts like map:
import com.softwaremill.quicklens._
case class C(d: Option[Int])
case class B(c: Option[C])
case class A(b: Option[B])
val a = A(b = None)
a.modify(_.b.each.c.each.d.each).setTo(3) // res0: A = A(None)
(the result is A(None), but how can we achieve a A(Some(B(Some(C(Some(3))))))?)
It could be useful if there were some operator (say, all) which can act as follows:
a.modify(_.b.all.c.all.d.all).setTo(3) // res0: A = A(Some(B(Some(C(Some(3))))))
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing .each operator and how nested Option paths are handled. Evaluate the proposed .all behavior against the examples in this issue, and consider the work complete when setting the nested value produces the requested chain of Some values with appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100