min
and max
are defined in Swift:
func max<T : Comparable>(x: T, y: T, rest: T...) -> T
func min<T : Comparable>(x: T, y: T, rest: T...) -> T
and used like so:
let min = min(1, 2)
let max = max(1, 2)
See this great writeup on documented & undocumented built-in functions in Swift.
More Related Contents:
- How to determine if a generic is an optional in Swift?
- Generic NSOperation subclass loses NSOperation functionality
- Extension of constructed generic type in Swift
- Returning constrained generics from functions and methods
- How do I require a generic type implement an operation like Add, Sub, Mul, or Div in a generic function?
- How do I use integer number literals when using generic types?
- How do I write the lifetimes for references in a type constraint when one of them is a local reference?
- How do I store a value of type Class in a Dictionary of type [String:Class] in Swift?
- What is the in-practice difference between generic and protocol-typed function parameters?
- How to use generic protocol as a variable type
- Why can’t I pass a Protocol.Type to a generic T.Type parameter?
- Why don’t associated types for protocols use generic type syntax in Swift?
- C# Adding two Generic Values
- Extend array types using where clause in Swift
- Matching a generic parameter to an associated type in an impl
- Generic Functions in Go
- How flatMap API contract transforms Optional input to Non Optional result?
- Usage of protocols as array types and function parameters in swift
- Why can’t `&(?Sized + Trait)` be cast to `&dyn Trait`?
- Generic function to sort array of class or struct by properties in Swift
- Why can’t I add a blanket impl on a trait with a type parameter?
- How do I add different types conforming to a protocol with an associated type to a collection?
- How can I make a generic type optional?
- A Swift protocol requirement that can only be satisfied by using a final class
- Calling a static method from a generic constraint Dart
- Generic extending class AND implements interface in Kotlin
- What does it mean to instantiate a Rust generic with an underscore?
- How do I write this member constraint in F#?
- How do I unwrap an arbitrary number of nested Option types?
- Xcode 7 Swift 2 impossible to instantiate UIViewController subclass of generic UITableViewController