Skip to content

Instantly share code, notes, and snippets.

@arnabmitra
Created January 25, 2016 04:27
Show Gist options
  • Save arnabmitra/31f3efcdf017b1541db2 to your computer and use it in GitHub Desktop.
Save arnabmitra/31f3efcdf017b1541db2 to your computer and use it in GitHub Desktop.
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Created by amitra on 1/24/16.
*/
public class Sample {
public static boolean isPrime(int n)
{
return n >1 && IntStream.range(2,n).noneMatch(i -> n % i ==0);
}
public static Double sumOfPrimeFunctional(int number,int sequence)
{
return Stream
.iterate(number,e -> e+1)
.filter(x -> isPrime(x))
.limit(sequence)
.map(Math::sqrt)
.reduce(0.0,Double::sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment