@wolfadex Thank you for pointing me to the phantom builder pattern! I was already planning on having the helper functions use extensible record types to work with both the DateTimeOptions
and DateOptions
when appropriate. It looks to me like this could be combined with the phantom builder pattern something like this:
module Cldr.Format.Options exposing (Options, ...)
type Options a b = Options b
type alias DateTimeOptions a =
Options a { year : ... , hour : ..., ... }
type alias DateOptions a =
Options a { year : ..., ... }
setYear : NumberOption -> Option {a | yearNotSetYet : () } {b | year : ... } -> Option a {b | year : ... }
If I understand correctly, this would allow for these to work:
initDateTimeOptions |> setMonthText Short |> setDay Numeric |> setHour Numeric
initDateOptions |> setMonthText Short |> setDay Numeric
but these would all throw compiler errors:
initDateTimeOptions |> setYear Numeric |> setYear TwoDigit
initDateOptions |> setHour Numeric
This would make the helper function API nice. The only way that people would be able to use the {defaultRecord | fields = updatedWhenNeeded }
pattern is if there is a separate function that converts that record into the tagged version.
If there was a helper function based API like above, would anyone still want to be able to use the record update syntax pattern?
- Yes, I want a record update syntax option
- No, the helper function pipeline is always good enough
0 voters