generic_function_tuple_map.carbon 425 B

123456789101112131415
  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. package ExecutableSemanticsTest api;
  5. fn map[T:! Type](f: fnty (T) -> T, tuple: (T, T)) -> (T, T) {
  6. return (f(tuple[0]), f(tuple[1]));
  7. }
  8. fn inc(x: i32) -> i32 { return x + 1; }
  9. fn main() -> i32 {
  10. return map(inc, (0, 2))[0];
  11. }