Add a `clamp` function to Algorithm.swift

I like the idea of a median free function a lot:

  • It's generally useful beyond just clamping.
  • It seems like a natural, missing peer to min and max.
  • It neatly avoids the question of if/how to handle half-open ranges.
  • For me, a free function is a more intuitive way to surface this functionality (struggling to articulate why).
1 Like