softwaremill / softwaremill/quicklens

Setting nested Options to Some(value)

Open
#39 6 comments 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

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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.