carbaj0
05/26/2020, 9:49 AMej : data class PersonalDataModel(
val firstName: Option<String>
)
firstName.modify(state){ //here i have a String instead of Option<String> }simon.vergauwen
05/26/2020, 9:51 AMoptics?
The reason for that is that an Optional is generated instead of a Lens.
https://arrow-kt.io/docs/0.10/optics/lens/
https://arrow-kt.io/docs/0.10/optics/optional/
Optional is a combination of copy with when to modify or getOption the focus.carbaj0
05/26/2020, 11:00 AM@optics
data class PersonalDataModel(
val firstName: InputModel,
val secondName: InputModel,
val firstLastName: InputModel,
val secondLastName: InputModel,
val birthDate: SpinnerModel,
val nationality: SpinnerListModel,
val birthPlace: Option<SpinnerModel>,
val gender: SpinnerListModel
) {
companion object
}
val initialState = PersonalDataModel(
......... ,
birthPlace = None
)
model.birthPlace.modify(state) { SpinnerModel("Birth Place", {}) } }carbaj0
05/26/2020, 11:01 AMsimon.vergauwen
05/26/2020, 11:31 AMf of modify over Nonecarbaj0
05/26/2020, 12:53 PMsimon.vergauwen
05/26/2020, 2:10 PMLens<PersonalDataModel, Option<SpinnerModel>> or Lens<PersonalDataModel, SpinnerModel?>.
Which currently is not autogenerated.
The reason you want to model it with a Lens instead of a Optional is because you then have the ability to control the Option rather than using the non-nullable SpinnerModel in Optional.simon.vergauwen
05/26/2020, 2:15 PMLens you’re dealing directly with the properties of a data class and you can set or get them, abstracting over properties and copy.
In the case of Prism you’re dealing with the properties of a subtype of a sealed class. This abstracts over when and copy, and it thus not have the same powers as Lens. Instead it can getOption the result from when or it attempt to modify if the correct subtype is found using when .
An Optional is the composition of a Prims and Lens which thus it has the same limitations as both combined.carbaj0
05/26/2020, 2:33 PM