Avatar
protocol NonEmptySequence: Sequence { ... } func max<S: Sequence>(_ sequence: S) -> S.Element? where S.Element: Comparable { ... } func max<S: NonEmptySequence>(_ sequence: S) -> S.Element where S.Element: Comparable { ... } let a: [Int] = [2, 3, 5] max(a) // Optional(5) let b: NonEmptyArray<Int> = [2, 3, 5] max(b) // 5
1:58 AM
maxmin で non optional になるのはうれしいなぁ。