generic_function_tuple_map.carbon 387 B

12345678910111213
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. fn map[T:! Type](f: fnty (T) -> T, tuple: (T, T)) -> (T, T) {
  5. return (f(tuple[0]), f(tuple[1]));
  6. }
  7. fn inc(x: Int) -> Int { return x + 1; }
  8. fn main() -> Int {
  9. return map(inc, (0, 2))[0];
  10. }