Is it possible to create a Setter which does nothi...
# arrow
d
Is it possible to create a Setter which does nothing? Simply returns the source without any changes. Or will this be an unlawful optic?
a
that won't satisfy the "get after set" rule
Copy code
lens.get(lens.set(x, v)) == v
d
Right! In my case though I don't need lens, only the setter. I have an utility function which sets the "progressBarVisible" in the UI State, but some UI States do not have this progress bar, so I wanted a Setter which does nothing, e.g.
Copy code
@optics
data class UiState1(title: String, progressBarVisible: Boolean)
@optics
data class UiState2(title: String)
and then
Copy code
cleverUpdate(
  titleLens = UiState1.title,
  progressBarVisibleSetter = UiState1.progressBarVisible
)
and I wondered what to do for
UiState2
here. But after I asked the question I discovered I could do this:
Copy code
cleverUpdate(
  titleLens = UiState2.title,
  progressBarVisibleSetter = { state, _ -> state } // this is a PSetter too
)