fsprojects / fsprojects/FSharpPlus
Using setl and view for the same optic in one function gives error "The type Data.Identity does not match the type Data.Const"
Open
Nobody has claimed this yet.
documentation
question
- Dominant language
- F#
- Stars
- 941
- Forks
- 106
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to use optics to set a record field together with the record's UpdatedAt: DateTimeOffset field only if the field value has changed.
I have created the following generic function, which doesn't compile:
let inline private setField valueOptic value updatedAtOptic now source =
let oldVal = view valueOptic source
if value = oldVal then source
else
setl valueOptic value source
|> setl updatedAtOptic now

What am I doing wrong?
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 with the inline setField function and reproduce the view/setl combination in a minimal F# example. Read how the optics API types view and setl, then verify that the function compiles and conditionally updates both the selected field and UpdatedAt.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100