Skip to content

Commit

Permalink
Add TailRec
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Sep 29, 2017
1 parent 7974b3c commit 3872659
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 2.1.0
version = 2.1.1
lombokVersion=1.16.12
joolVersion=0.9.12
pCollectionsVersion=2.1.2
Expand Down
1 change: 1 addition & 0 deletions src/jmh/java/scrabble/IdenticalToStream.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//JMH Benchmarking test file : not part of distribution
/*
* Copyright (C) 2015 José Paumard
*
Expand Down
1 change: 1 addition & 0 deletions src/jmh/java/scrabble/IterableSpliterator.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//JMH Benchmarking test file : not part of distribution
/*
* Copyright (C) 2015 José Paumard
*
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/scrabble/IxScanLeftTakeRight.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


import ix.*;

//JMH Benchmarking test file : not part of distribution
/**
* Shakespeare plays Scrabble with Ix.
* @author José
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/scrabble/NonParallelStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

//JMH Benchmarking test file : not part of distribution
/**
* Shakespeare plays Scrabble with Java Streams.
* @author José
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/scrabble/ScanLeftTakeRight.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.function.Function;



//JMH Benchmarking test file : not part of distribution
/**
* Shakespeare plays Scrabble with Ix optimized.
* @author José
Expand Down
1 change: 1 addition & 0 deletions src/jmh/java/scrabble/ShakespearePlaysScrabble.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//JMH Benchmarking test file : not part of distribution
/*
* Copyright (C) 2015 José Paumard
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;

//JMH Benchmarking test file : not part of distribution
/**
* Shakespeare plays Scrabble with Streams.
* @author José
Expand Down
1 change: 1 addition & 0 deletions src/jmh/java/scrabble/Util.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//JMH Benchmarking test file : not part of distribution
/*
* Copyright (C) 2015 José Paumard
*
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/cyclops/control/ReaderWriterState.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.aol.cyclops2.hkt.Higher;
import com.aol.cyclops2.hkt.Higher4;
import cyclops.async.Future;
import cyclops.collections.immutable.LinkedListX;
import cyclops.monads.Witness;
import cyclops.monads.Witness.rws;
Expand Down Expand Up @@ -37,6 +38,11 @@ public Tuple3<W,S,T> run(R r,S s) {
return Fn0.run(runState.apply(r,s));
}

public static <T,R1, W, S, R> ReaderWriterState<R1, W, S, R> tailRec(Monoid<W> monoid,T initial, Function<? super T, ? extends ReaderWriterState<R1, W, S, ? extends Xor<T, R>>> fn) {
Higher<Higher<Higher<Higher<rws, R1>, W>, S>, R> x = Instances.<R1,W,S> monadRec(monoid).tailRec(initial, fn);
return narrowK(x);
}

public ReaderWriterState<R,W,S,T> tell(W value) {
BiFunction<? super R, ? super S, Free<supplier,Tuple3<W,S, T>>> fn =
(r,s)->runState.apply(r,s).map(t3-> tuple(monoid.apply(t3.v1,value),t3.v2,t3.v3));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cyclops/control/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ public <R1, R4> State<S,R4> forEach2(Function<? super T, State<S,R1>> value2,
});

}
public static <S,T,R> State<S, R> tailRec(T initial, Function<? super T, ? extends State<S, ? extends Xor<T, R>>> fn) {
return narrowK( State.Instances.<S> monadRec().tailRec(initial, fn));

}


public static <S, T> State<S, T> state(Function<? super S,? extends Tuple2<S, T>> runF) {
Expand Down

0 comments on commit 3872659

Please sign in to comment.