Closed Fl4m3Ph03n1x closed 5 years ago
You could probably start by looking at the Ramda implementation and then going from there. It should be pretty similar, but swap out gt
and lt
for the >
and <
operators.
How does this implementation look?
// clamp :: Ord a => a -> a -> a -> a
const clamp = lower => upper => S.compose (S.min (upper)) (S.max (lower));
So, the name speaks for itself. I vote we should implement R.clamp and I agree with the interface given by @davidchambers
S.clamp :: Ord a => a -> a -> a -> a
This means we would not only be able to clamp Numbers, but also Strings and pretty much anything that has an order.
As for implementation ... I would have no idea on how to implement it ....