-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2200285
commit 50b2bfa
Showing
3 changed files
with
104 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cyclops; | ||
|
||
import com.aol.cyclops.vavr.hkt.ListKind; | ||
import com.aol.cyclops2.hkt.Higher; | ||
import cyclops.async.Future; | ||
|
||
import cyclops.companion.vavr.Lists; | ||
import cyclops.companion.vavr.Streams; | ||
import cyclops.control.Xor; | ||
import cyclops.monads.VavrWitness; | ||
import cyclops.monads.VavrWitness.list; | ||
import cyclops.monads.VavrWitness.stream; | ||
import cyclops.stream.ReactiveSeq; | ||
import cyclops.typeclasses.monad.MonadRec; | ||
import io.vavr.collection.List; | ||
import io.vavr.collection.Stream; | ||
import org.junit.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
|
||
|
||
public class MonadRecTest { | ||
|
||
@Test | ||
public void listTest(){ | ||
MonadRec<list> mr = Lists.Instances.monadRec(); | ||
List<Integer> l = Lists.tailRecXor(0, i -> i < 100_000 ? List.of(Xor.secondary(i + 1)) : List.of(Xor.primary(i + 1))); | ||
assertThat(l,equalTo(List.of(100_001))); | ||
} | ||
@Test | ||
public void streamTest(){ | ||
MonadRec<stream> mr = Streams.Instances.monadRec(); | ||
Stream<Integer> l = Streams.tailRecXor(0, i -> i < 100_000 ? Stream.of(Xor.secondary(i + 1)) : Stream.of(Xor.primary(i + 1))); | ||
assertThat(l,equalTo(Stream.of(100_001))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cyclops; | ||
|
||
import cyclops.companion.vavr.Streams; | ||
import io.vavr.collection.Stream; | ||
import org.junit.Test; | ||
|
||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Created by johnmcclean on 08/08/2017. | ||
*/ | ||
public class StreamsTest { | ||
|
||
@Test | ||
public void simpleFoldRight(){ | ||
assertThat(Streams.foldRight(Stream.of(1,2,3),0,(a,b)->a+b),equalTo(6)); | ||
} | ||
@Test | ||
public void stackBuster(){ | ||
assertThat(Streams.foldRight(Stream.range(0,100_000),0,(a,b)->a+b),equalTo(704982704)); | ||
} | ||
} |