Skip to content

Setting nested Options to Some(value) #39

@oripwk

Description

@oripwk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions