<commit_before>import check { ... }

Element? find<Element>(Array<Element> a, Boolean f(Element x)) {
  for (Element e in a) {
    if (f(e)) {
      return e;
    }
  }
  return null;
}

Element? find2<Element>(Array<Element> a, Boolean f(Element x) => true) {
  for (Element e in a) {
    if (f(e)) {
      return e;
    }
  } else {
    return null;
  }
}

Callable<String, [Integer]> subtract(Integer howMuch) {
  return (Integer i) => (i-howMuch).string;
}

void testAnonymous() {
  print("Testing anonymous functions...");
  value nums = array{1,2,3,4,5};
  //Test positional argument call
  variable value found = find(nums, (Integer i) => i%2==0);
  if (exists i=found) {
    check(i == 2, "anonfunc positional");
  } else { fail("anonfunc positional"); }
  //Named argument call
  found = find{
    function f(Integer i) {
      return i%2==0;
    }
    a=nums;
  };
  if (exists i=found) {
    check(i == 2, "anonfunc named");
  } else { fail("anonfunc named"); }

  //Gavin's test
  void callFunction(String f(Integer i), String expect) {
    check(f(0)==expect, "anon func returns ``f(0)`` instead of ``expect``");
  }

  function f(Integer i) {
    return (i+12).string;
  }
  callFunction(f, "12");

  callFunction((Integer i) => (i*3).string, "0");

  callFunction {
    expect = "0";
    function f(Integer i) {
      return (i^2).string;
    }
  };

  value f2 = (Integer i) => (i-10).string;
  callFunction(f2, "-10");
  callFunction(subtract(5), "-5");
  //As defaulted param
  found = find2(nums, (Integer i) => i>2);
  if (exists i=found) {
    check(i==3, "anonfunc i>2 [1]");
  } else { fail("anonfunc i>2 [2]"); }
  found = find2(nums);
  if (exists i=found) {
    check(i==1, "anonfunc defaulted param [1]");
  } else { fail("anonfunc defaulted param [2]"); }
}
<commit_msg>add an interface to be found by metamodel tests<commit_after>import check { ... }

Element? find<Element>(Array<Element> a, Boolean f(Element x)) {
  for (Element e in a) {
    if (f(e)) {
      return e;
    }
  }
  return null;
}

Element? find2<Element>(Array<Element> a, Boolean f(Element x) => true) {
  for (Element e in a) {
    if (f(e)) {
      return e;
    }
  } else {
    return null;
  }
}

Callable<String, [Integer]> subtract(Integer howMuch) {
  return (Integer i) => (i-howMuch).string;
}

void testAnonymous() {
  print("Testing anonymous functions...");
  value nums = array{1,2,3,4,5};
  //Test positional argument call
  variable value found = find(nums, (Integer i) => i%2==0);
  if (exists i=found) {
    check(i == 2, "anonfunc positional");
  } else { fail("anonfunc positional"); }
  //Named argument call
  found = find{
    function f(Integer i) {
      return i%2==0;
    }
    a=nums;
  };
  if (exists i=found) {
    check(i == 2, "anonfunc named");
  } else { fail("anonfunc named"); }

  //Gavin's test
  void callFunction(String f(Integer i), String expect) {
    check(f(0)==expect, "anon func returns ``f(0)`` instead of ``expect``");
  }

  function f(Integer i) {
    return (i+12).string;
  }
  callFunction(f, "12");

  callFunction((Integer i) => (i*3).string, "0");

  callFunction {
    expect = "0";
    function f(Integer i) {
      return (i^2).string;
    }
  };

  value f2 = (Integer i) => (i-10).string;
  callFunction(f2, "-10");
  callFunction(subtract(5), "-5");
  //As defaulted param
  found = find2(nums, (Integer i) => i>2);
  if (exists i=found) {
    check(i==3, "anonfunc i>2 [1]");
  } else { fail("anonfunc i>2 [2]"); }
  found = find2(nums);
  if (exists i=found) {
    check(i==1, "anonfunc defaulted param [1]");
  } else { fail("anonfunc defaulted param [2]"); }
}

shared interface LeaveThereHereForMetamodelTests{}

{'fraction_non_alphanumeric': 0.18250950570342206, 'fraction_numerical': 0.022270505160239002, 'mean_word_length': 3.1710079275198186, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1203734', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1344, 'n_words': 359}