-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat single-case union as the value #26
Comments
I've seen its common to add a
Maybe that can be the cue that it should format it as such, and not as a normal union? 🤔 |
We were recently discussing this exact feature with @thinkbeforecoding! It isn't supported yet, but it would make a lot of sense. |
I and others have recently taken to using FSharp.UMX for this sort of stuff (example, which has the benefit (if the underlying type is |
@bartelink : I tried out FSharp.UMX now. It looks very nice! I'm tempted to replace all our usage on single-cased DUs with this. Is there any reason to be hesitant about doing this? Do you advice for or against it? |
Yes, Eirik and Alfonso have done us a great service; I've used it in quite a few contexts and find it hard to fault in general. Some things to point out:
let (|Id|) (x : Guid) = x.ToString "N" |> FSharp.UMX.UMX.tag
let inline mkId () = Guid.NewGuid() |> (|Id|)
let (|Ids|) (xs : Guid[]) = xs |> Array.map (|Id|)
let (|ToList|) (xs : 'T[]) = Array.toList xs
let [<Property>] prop (Ids (ToList tickets), Ids items) =
... (where tickets is a XyzId[] and items is an AbcId list) The samples folder in Equinox has some some usages that you might want to peep around - I also have comments around this stuff (none of this is actually using STJ yet - that's a big TODO in jet/FsCodec#14, hence my lurking here!) https://github.com/jet/equinox/blob/master/samples/Store/Domain/Infrastructure.fs#L40 |
I would expect person to be formatted as
{name: "Tarmil", personId: 123}
in the example above, not as:{name: "Tarmil", personId: {Item: 123}}
which is the closest thing I've found using options:JsonUnionEncoding.BareFieldlessTags ||| JsonUnionEncoding.Untagged
.Is it possible to add a super simple formatter specifically for Single-Case DUs? They're a really common pattern in F#, and we're using them to wrap basically all our primitives to add semantic meaning to them.
E.g. Map<PersonId, ProfileInfo> makes a lot more sense than Map<string, ProfileInfo> in which case you have to remember that the string refers to a person id. Single-Case DUs makes everything very easy to comprehend 😄
Maybe there already is support for it?
The text was updated successfully, but these errors were encountered: