Open silasdavis opened 10 months ago
Well reading the ticket linked above again (https://github.com/gcanti/fp-ts/issues/1636) having tried to solve the problem myself, perhaps this is exactly a dupe of that!
Side-question: not sure why the above compiles, but I am nesting options in my usage.
Is there an existing function idiom for taking (x: undefined | A | Option<A>) => Option<A>
?
Forgive my abuse of the issue types, I'm not sure if this is a feature request, perhaps there is a clean way to handle it.
I would like to define a custom
Semigroup
for merging structs. To preserve a sane typescript interface I'd like the input type to my merging function to be:I can define a
Semigroup
that does what I want by replacing the optional fields with suitable zero values usingOption
fortoken
.Below is a solution that first normalise the input values into a type that is easier to work with in fp-ts, however it involves additional boilerplate which is a bit of a shame. Namely:
PartialOptions
fromOptions
(with a nod to io-ts I would like to define my 'runtime types' once and infer the compile-time type via dependenttypeof
types.optionify
function a bit but with the primitive I know about/understand it would be more work than just defining it explicitly.This ticket looks like it is dealing with just the same flavour of problem: https://github.com/gcanti/fp-ts/issues/1636
Here's a test case demonstrating what I'm thinking of:
If this is a poor fit for the issues section here then my apologies and I will close it.