Skip to content

Instantly share code, notes, and snippets.

View rakeshopensource's full-sized avatar

Rakesh Rathi rakeshopensource

View GitHub Profile
@rakeshopensource
rakeshopensource / Prime.java
Created April 5, 2018 08:10
Prime numbers with Java8 Stream API
import java.util.stream.IntStream;
public class Prime {
public static void main(String[] args) {
IntStream.rangeClosed(1, 100)
.filter(i -> IntStream.rangeClosed(2, (int) Math.sqrt(i))
.noneMatch(j -> i % j == 0 && i != 1)
)
.forEach(System.out::println);
@rakeshopensource
rakeshopensource / pc.go
Created February 24, 2018 17:33
Producer Consumer problem implementation in golang
package main
import (
"fmt"
"strconv"
"time"
)
var done = make(chan string)
func producer(c chan<- string) {
@rakeshopensource
rakeshopensource / LoanPattern.java
Created February 17, 2018 16:18
Loan Pattern using Java8
import java.util.function.Consumer;
class MailBuilder {
private String from;
private String to;
private String subject;
private String body;
public MailBuilder from(final String fromAddress) {
this.from = fromAddress;
@rakeshopensource
rakeshopensource / FunctionAndPredicate.java
Created February 17, 2018 16:04
Java8 Function and Predicate Example
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public class FunctionAndPredicate {
@rakeshopensource
rakeshopensource / Factorial.java
Last active June 25, 2019 09:01
Factorial with Java8 Stream API
import java.math.BigInteger;
import java.util.stream.Stream;
@FunctionalInterface
interface Call<T> {
Call<T> apply();
default boolean isComplete() {
return false;