generic_function_apply.carbon 413 B

12345678910111213141516171819
  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 apply[T:! Type, U:! Type](f: fnty (T) -> U, x: T) -> U {
  5. return f(x);
  6. }
  7. fn positive(x: Bool) -> i32 {
  8. if (x) {
  9. return 2;
  10. } else {
  11. return -2;
  12. }
  13. }
  14. fn main() -> i32 {
  15. return apply(positive, false);
  16. }