Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
27
Task/Function-definition/Java/function-definition-2.java
Normal file
27
Task/Function-definition/Java/function-definition-2.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public final class FunctionDefinition {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(size.apply("Rosetta"));
|
||||
System.out.println(greeting.apply("Joe"));
|
||||
System.out.println(half.applyAsDouble(7));
|
||||
System.out.println(lessThanTen.test(15));
|
||||
System.out.println(add.apply(2, 3));
|
||||
}
|
||||
|
||||
private static Function<String, Integer> size = s -> s.length();
|
||||
|
||||
private static UnaryOperator<String> greeting = s -> "Hello " + s;
|
||||
|
||||
private static DoubleUnaryOperator half = a -> a / 2;
|
||||
|
||||
private static Predicate<Integer> lessThanTen = a -> a < 10;
|
||||
|
||||
private static BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
|
||||
|
||||
}
|
||||
|
|
@ -1,2 +1,8 @@
|
|||
var multiply = (a, b) => a * b;
|
||||
var multiply = (a, b) => { return a * b };
|
||||
|
||||
// Or, `var` being long deprecated, and currying convenient,
|
||||
// (particularly in use with the higher-order Array methods)
|
||||
|
||||
const multiply = a =>
|
||||
b => a * b;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
let prod(a, b) := a*b
|
||||
let prodAnon := (a, b) -> a*b
|
||||
|
||||
assert(prodAnon(2, 2) = ((a, b) -> a*b)(2, 2))
|
||||
assert(prod(2, 2) = prodAnon(2, 2))
|
||||
15
Task/Function-definition/YAMLScript/function-definition.ys
Normal file
15
Task/Function-definition/YAMLScript/function-definition.ys
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
!yamlscript/v0
|
||||
|
||||
# Main function definition with variable arguments:
|
||||
defn main(*args):
|
||||
say: "multiply($(args.join(', ')))
|
||||
-> $multiply(args*)"
|
||||
|
||||
# A multi-arity function definition:
|
||||
defn multiply:
|
||||
(): 1
|
||||
(x): x
|
||||
(x y): x * y
|
||||
(x y *more):
|
||||
reduce multiply:
|
||||
multiply(x y) more
|
||||
Loading…
Add table
Add a link
Reference in a new issue