Skip to content

Instantly share code, notes, and snippets.

@ha1f
Created October 31, 2019 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ha1f/a5bfc0ef294f2f43c4dc471c2a1ff55b to your computer and use it in GitHub Desktop.
Save ha1f/a5bfc0ef294f2f43c4dc471c2a1ff55b to your computer and use it in GitHub Desktop.
//
// Comparable+Clamp.swift
//
import Foundation
extension Comparable {
/// minとmaxの範囲に収める
func clamp(min minValue: Self, max maxValue: Self) -> Self {
return max(min(self, maxValue), minValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment