apply.carbon 486 B

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