エントリーの編集
エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています
- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来2. 7. func sum<T : Numeric>(of v... Protocol-Oriented Integers に想うジェネリックプログラミングの未来2. 7. func sum<T : Numeric>(of values: Array<T>) -> T { return values.reduce(0) { $0 + $1 } } // Int の配列でも、Float の配列でも、使える let integers = [5, 5, 5, 5] let floats = [2.5, 2.5, 2.5, 2.5] as [Float] sum(of: integers) // 20 sum(of: floats) // 10 10. func average <C:Collection> (of values: C ) -> C.Element where C.Element : BinaryInteger { return values.red