S.min ('1') ('02') =>'02'
Why is this even possible? (yes type coercion... but this is Sanctuary) Can Sanctuary be configured so that Nothing is returned when Strings are used? Is there an elegant way to deal with this?
S.min ('1') ('02') =>'02'
Why is this even possible? (yes type coercion... but this is Sanctuary) Can Sanctuary be configured so that Nothing is returned when Strings are used? Is there an elegant way to deal with this?
Let's consider the type of
S.min
:String
satisfies the requirements of Ord, soString -> String -> String
is one possible specialization:If you are dealing with inputs that should be numbers but may not be, the best approach is to deal with the uncertainty up front:
Then, you could use
S.lift2
to transformS.min
into a function that can operate onMaybe Number
values:The signature above can be specialized like so:
The final step is to apply
S.lift2 (S.min)
to the trusted inputs:Here is a full working example: