apply.carbon 485 B

123456789101112131415161718192021222324
  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. //
  5. // AUTOUPDATE
  6. // CHECK:STDOUT: result: -2
  7. package ExplorerTest api;
  8. fn apply[T:! type, U:! type](f: __Fn (T) -> U, x: T) -> U {
  9. return f(x);
  10. }
  11. fn positive(x: bool) -> i32 {
  12. if (x) {
  13. return 2;
  14. } else {
  15. return -2;
  16. }
  17. }
  18. fn Main() -> i32 {
  19. return apply(positive, false);
  20. }