Sanctuary: Implementation of R.clamp

Created on 1 Aug 2018  路  2Comments  路  Source: sanctuary-js/sanctuary

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 ....

Most helpful comment

How does this implementation look?

//    clamp :: Ord a => a -> a -> a -> a
const clamp = lower => upper => S.compose (S.min (upper)) (S.max (lower));

All 2 comments

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));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidchambers picture davidchambers  路  8Comments

Siilwyn picture Siilwyn  路  5Comments

svozza picture svozza  路  8Comments

toolsh picture toolsh  路  6Comments

zfoxdev picture zfoxdev  路  8Comments