oliverbooth / X10D

Extension methods on crack.
https://oliverbooth.github.io/X10D/
MIT License
28 stars 2 forks source link

IComparable<T>.Clamp #24

Closed oliverbooth closed 3 years ago

oliverbooth commented 3 years ago

Type

System.IComparable<T>

Extension method signature

T Clamp<T>(T, T);
Parameters Parameter Type Description
lower T The lower bound of the result.
upper T The upper bound of the result.

Description Returns the current value clamped to the inclusive range of lower and upper.

Benefits Math.Clamp only supports primitives and does not support generic types.

Drawbacks None considered (at this time)

(Optional) Implementation example

{
    return value.Max(lower).Min(upper);
}
oliverbooth commented 3 years ago

Implemented with dd66fb9a2b2476f3d4e4d5c3b504a9ceb76a5cee