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
#344 23 comments 0 reactions 0 assignees View on GitHub

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

image

What am I doing wrong?

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.