Avatar
↑のタプルに対する操作を可変長型パラに拡張して func square<T...>(of values: (T...)) -> (T...) { values.map { $0 * $0 } } square(of: (3, 5.0, Complex<Double>.i)) // (9, 25.0, (-1.0, 0.0)) func firsts<(S: Sequence)...>(of sequences: (S...)) -> ((S.Element?)...) { sequences.map { $0.first } } firsts(of: ([2, 3, 5], "XYZ", 42...)) // (2, "X", 42) func descriptions<(T: CustomStringConvertible)...>(of values: (T...)) -> (String...) { values.map { $0.description } } descriptions(of: (42, true, "XYZ")) // ("42", "true", "XYZ") func sum<(T: IntConvertible)...>(of values: (T...)) -> Int { values.reduce(0) { $0 + $1.asInt() } } sum(of: (3, 5.0, "7")) // 15