Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created April 9, 2015 00:42
Show Gist options
  • Save nobeans/068f2feaa85b8cffd6bb to your computer and use it in GitHub Desktop.
Save nobeans/068f2feaa85b8cffd6bb to your computer and use it in GitHub Desktop.
def average = { double v, int count ->
double sum = 0;
for (int i = 0; i < count; i++) {
sum += v;
}
return sum / count;
}
println average(0.1d, 10)
def average2 = { double v, int count ->
return java.util.stream.DoubleStream.generate({ v }).limit(count).average().orElse(0)
}
println average2(0.1d, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment