First-class functions/Use numbers analogously: Difference between revisions

New post.
(added Arturo)
(New post.)
Line 834:
 
Please refer to [http://rosettacode.org/wiki/First-class_functions#Tacit_.28unorthodox.29_version First-class functions tacit (unorthodox) version] for the definitions of the functions train, an and of.
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
 
public class FirstClassFunctionsUseNumbersAnalogously {
 
public static void main(String[] args) {
final double x = 2.0, xi = 0.5,
y = 4.0, yi = 0.25,
z = x + y, zi = 1.0 / ( x + y );
 
List<Double> list = Arrays.asList( x, y, z );
List<Double> inverseList = Arrays.asList( xi, yi, zi );
BiFunction<Double, Double, Function<Double, Double>> multiplier = (a, b) -> product -> a * b * product;
for ( int i = 0; i < list.size(); i++ ) {
Function<Double, Double> multiply = multiplier.apply(list.get(i), inverseList.get(i));
final double argument = (double) ( i + 1 );
System.out.println(multiply.apply(argument));
}
}
 
}
</syntaxhighlight>
{{ out }}
<pre>
1.0
2.0
3.0
</pre>
 
=={{header|jq}}==
884

edits