Skip to content

Commit

Permalink
5.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Jul 3, 2015
1 parent 79d872a commit 728276d
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 93 deletions.
2 changes: 1 addition & 1 deletion cyclops-all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
dependencies {

compile project(':cyclops-try')
compile project(':cyclops-switch')
compile project(':cyclops-feature-toggle')
compile project(':cyclops-tuples')
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
Expand Down
1 change: 1 addition & 0 deletions cyclops-converters/repos/cyclops-converters-1.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7c1e44ff9dd0ab387bcde7cf6b26528e534b2d8a
29 changes: 29 additions & 0 deletions cyclops-converters/repos/ivy-1.0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="com.aol.cyclops" module="cyclops-converters" revision="1.0" status="integration" publication="20150703134609">
<description/>
</info>
<configurations>
<conf name="archives" visibility="public" description="Configuration for archive artifacts."/>
<conf name="compile" visibility="private" description="Compile classpath for source set 'main'."/>
<conf name="default" visibility="public" description="Configuration for default artifacts." extends="runtime"/>
<conf name="runtime" visibility="private" description="Runtime classpath for source set 'main'." extends="compile"/>
<conf name="testCompile" visibility="private" description="Compile classpath for source set 'test'." extends="compile"/>
<conf name="testRuntime" visibility="private" description="Runtime classpath for source set 'test'." extends="runtime,testCompile"/>
</configurations>
<publications>
<artifact name="cyclops-converters" type="jar" ext="jar" conf="archives,runtime"/>
</publications>
<dependencies>
<dependency org="com.google.guava" name="guava" rev="18.0" conf="compile-&gt;default"/>
<dependency org="com.aol.simplereact" name="simple-react" rev="0.96" conf="compile-&gt;default"/>
<dependency org="com.javaslang" name="javaslang" rev="1.2.0" conf="compile-&gt;default"/>
<dependency org="com.nurkiewicz.lazyseq" name="lazyseq" rev="0.0.1" conf="compile-&gt;default"/>
<dependency org="org.projectlombok" name="lombok" rev="1.14.2" conf="compile-&gt;default"/>
<dependency org="org.functionaljava" name="functionaljava" rev="4.3" conf="compile-&gt;default"/>
<dependency org="org.functionaljava" name="functionaljava-java8" rev="4.3" conf="compile-&gt;default"/>
<dependency org="org.hamcrest" name="hamcrest-all" rev="1.3" conf="compile-&gt;default"/>
<dependency org="junit" name="junit" rev="4.12" conf="testCompile-&gt;default"/>
<dependency org="org.mockito" name="mockito-all" rev="1.9.5" conf="testCompile-&gt;default"/>
</dependencies>
</ivy-module>
1 change: 1 addition & 0 deletions cyclops-converters/repos/ivy-1.0.xml.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4570f09de2d8027af0b67edccda841bc25945264
6 changes: 3 additions & 3 deletions cyclops-feature-toggle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {
}

dependencies {
// compile 'com.aol.advertising.cyclops:cyclops-core:3.0.0'

compile project(':cyclops-core')
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
Expand All @@ -37,13 +37,13 @@ test {

modifyPom {
project {
name 'cyclops-pattern-matching'
name 'cyclops-feature-toggle'
description 'Enabled / Disabled monad (extends javaslang.control.Either)'
url 'http://advertising.com'
inceptionYear '2015'

groupId 'com.aol.cyclops'
artifactId 'enable-switch'
artifactId 'cyclops-feature-toggle'
version "$version"

scm {
Expand Down
126 changes: 46 additions & 80 deletions cyclops-for-comprehensions/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ Simplify deeply nested looping (over Collections, even Streams, Optionals and m

Two supported formats

1. do nototation
2. scala like syntax
1. Type Do Notation via Do.add / with
2. Untpyed Do Notation via UntypedDo.add / with



# Do Notation

List<Integer> list= Arrays.asList(1,2,3);

Stream<Integer> stream = Do.with(list)
Stream<Integer> stream = Do.add(list)
.yield((Integer i)-> i +2);
Expand All @@ -35,24 +35,24 @@ Yield, Filter and 'and' take curried functions

(That is a chain of single input parameter functions)

Stream<Integer> stream = Do.with(asList(20,30))
.and((Integer i)->asList(1,2,3))
.yield((Integer i)-> (Integer j) -> i + j+2);
Stream<Integer> stream = Do.add(asList(20,30))
.with( i->asList(1,2,3))
.yield(i-> j -> i + j+2);

Parameters are stack based, the parameter to the first function is an index into the first Collection or Monad, the parameter to the second function is an index into the second Collection or Monad and so on.

The above code could be rewritten as

Stream<Integer> stream = Do.with(asList(20,30))
.and((Integer any)->asList(1,2,3))
.yield((Integer x)-> (Integer y) -> x + y+2);
Stream<Integer> stream = Do.add(asList(20,30))
.with(any->asList(1,2,3))
.yield(x-> y -> x + y+2);

And it would work in exactly the same way

List<Integer> list= Arrays.asList(1,2,3);
Stream<Integer> stream = Do.with(list)
.filter((Integer a) -> a>2)
.yield((Integer a)-> a +2);
Stream<Integer> stream = Do.add(list)
.filter(a -> a>2)
.yield(a-> a +2);
Expand All @@ -76,15 +76,14 @@ We can iterate over them using Java 5 'foreach' syntax

The equivalent for comprehension would be

ForComprehensions.foreach1(c -> c.mapAs$1(list)
.run( (Vars1<String> v) -> System.out.println(v.$1())
or with Do Notation

Do.with(list)
.yield( (String element) -> {System.out.println(element); return null; } );
Do.add(list)
.yield( element -> element )
.forEach(System.out::println);
We have simply converted the list to a Stream and are using Stream forEach to iterate over it.

If we nest our looping
But.. if we nest our looping

List<Integer> numbers = Arrays.asList(1,2,3,4);

Expand All @@ -96,15 +95,11 @@ If we nest our looping

Things start to become a little unwieldy, but a little less so with for comprehensions

ForComprehensions.foreach2(c -> c.flatMapAs$1(list)
.mapAs$2((Vars2<String,Integer> v)->numbers)
.run(v -> System.out.println(v.$1()+v.$2())

With Do notation

Do.with(list)
.and((String element) -> numbers)
.yield( (String element) -> (Integer num) -> {System.out.println(element + num); return null; } );

Do.add(list)
.with(element -> numbers)
.yield( element -> num -> element + num )
.forEach(System.out::println);


Let's add a third level of nesting
Expand All @@ -122,18 +117,12 @@ Let's add a third level of nesting

And the for comprehension looks like

ForComprehensions.foreach3(c -> c.flatMapAs$1(list)
.flatMapAs$2((Vars<String,Integer,Date> v) -> numbers)
.mapAs$2(v -> dates)
.run( v-> System.out.println(v.$1()+v.$2()+v.$3())


With Do notation

Do.with(list)
.andJustAdd(numbers)
.andJustAdd(dates)
.yield( (String element) -> (Integer num) -> (Date date) -> {System.out.println(element + num+":"+date) ; return null; } );

Do.add(list)
.add(numbers)
.add(dates)
.yield( element -> num -> date -> element + num+":"+date )
.forEach(System.out::println);


Stream map
Expand All @@ -153,27 +142,30 @@ Can be written as

Running a for comprehension over a list (stream) and an Optional

val strs = Arrays.asList("hello","world"); //using Lombok val
val opt = Optional.of("cool");

List<String> strs = Arrays.asList("hello","world");
Optional<String> opt = Optional.of("cool");
Seq<String> results = ForComprehensions.foreach2( c-> c.flatMapAs$1(strs)
.mapAs$2((Vars2<String,String> v) -> opt)
.yield( v -> v.$1() + v.$2()));
Do.add(strs)
.add(opt)
.yield(v1->v2 -> v1 + v2)
.forEach(System.out::println);
Outputs : [hellocool, worldcool]


Or the other way around


val strs = Arrays.asList("hello","world");
val opt = Optional.of("cool");
List<String> strs strs = Arrays.asList("hello","world");
Optional<String> opt = Optional.of("cool");
Optional<List<String>> results = ForComprehensions.foreach2( c-> c.flatMapAs$1(opt)
.mapAs$2( (Vars2<String,String> v) -> strs)
.yield( v -> v.<String>$1() + v.$2()));
Do.add(opt)
.add(strs)
.yield(v1->v2 -> v1+ v2)
.<String>toSequence()
.forEach(System.out::println);
assertThat(results.get(),hasItem("coolhello"));
assertThat(results.get(),hasItem("coolworld"));
Expand Down Expand Up @@ -223,23 +215,9 @@ Cyclops for comphrensions allow deeply nested iterations or monadic operations t

The Cyclops implementation is pure Java however, and although it will revert to dynamic execution when it needs to, reflection can be avoided entirely.

### Features
### Custom interfaces


1. Nested iteration over Collections & Maps
* Nested iteration over JDK 8 Monads - Stream, Optional, CompletableFuture
* Nested iteration over any external Monad e.g. Functional Java, Javaslang, TotallyLazy (by reflection, or register a Comprehender)
* Strict and looser typing
* Fluent step builder interfaces with semantic naming
* Built in support for 3 levels of nesting

stream.flatMap ( s1 -> stream2.flatMap( s2 -> stream3.map (s3 -> s3+s2+s1)));

foreach3 (c -> c.flatMapAs$1(stream)
.flatMapAs$2(stream2)
.mapAs$3(stream3)
.yield(()->$3()+$2()+$1());

* Support for custom interface definition with virtually unlimited nesting

Stream<Integer> stream = foreachX(Custom.class,
Expand All @@ -251,19 +229,7 @@ The Cyclops implementation is pure Java however, and although it will revert to
Optional<Integer> empty = Optional.empty();
BiFunction<Integer,Integer,Integer> f2 = (a,b) -> a *b;
Object result = foreach2(c -> c.flatMapAs$1(one)
.mapAs$2(v->empty)
.yield((Vars2<Integer,Integer> v)->{return f2.apply(v.$1(), v.$2());}));

Each call to $ results in flatMap call apart from the last one which results in map. guard can be used for filtering.
The c.$1() and c.$2() calls capture the result of the operations at c.$1(_) and c.$2(_).

### There are 4 For Comphrension classes

* ForComprehensions :- static foreach methods with looser typing, and provides entry point to custom For Comprehensions
* ForComprehension1 :- Stricter typing, offers $1 operations only
* ForComprehension2 :- Stricter typing, offer $1 and $2 operations
* ForComprehension3 :- Stricter typing, offer $1, $2 and $3 operations


### Auto-Seq upscaling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertThat;

import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -14,9 +15,17 @@


public class DoFiltersTest {

static class Bean {
public Integer getNumber(){
return null;
}
}
public Bean getCount(){
return null;
}
@Test
public void do2(){

Stream<Double> s = Do.add(asList(10.00,5.00,100.30))
.withCollection( d-> asList(2.0))
.filter(d-> e -> (e*d)>10.00)
Expand All @@ -25,6 +34,10 @@ public void do2(){
val total = s.collect(Collectors.summingDouble(t->t));
assertThat(total,equalTo(330.9));
}
private Object getPerson() {
// TODO Auto-generated method stub
return null;
}
@Test
public void do1(){
Stream<Double> s = Do.add(asList(10.00,5.00,100.30))
Expand Down
2 changes: 1 addition & 1 deletion cyclops-free-monad/repos/cyclops-free-monad-1.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1ec4d00bc7f309720c94afb8c339c32ddd5ba2be
82048630f04463f5471cfc8e0c61f1f9d3b4e75b
10 changes: 5 additions & 5 deletions cyclops-free-monad/repos/ivy-1.0.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="com.aol.cyclops" module="cyclops-free-monad" revision="1.0" status="integration" publication="20150604003101">
<info organisation="com.aol.cyclops" module="cyclops-free-monad" revision="1.0" status="integration" publication="20150703134648">
<description/>
</info>
<configurations>
Expand All @@ -17,10 +17,10 @@
<dependencies>
<dependency org="org.functionaljava" name="functionaljava" rev="4.3" conf="compile-&gt;default"/>
<dependency org="org.functionaljava" name="functionaljava-java8" rev="4.3" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-pattern-matching" rev="4.0.1" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-trampoline" rev="4.0.1" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-base" rev="4.0.1" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-for-comprehensions" rev="4.0.1" conf="testCompile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-pattern-matching" rev="5.0.0" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-trampoline" rev="5.0.0" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-base" rev="5.0.0" conf="compile-&gt;default"/>
<dependency org="com.aol.cyclops" name="cyclops-for-comprehensions" rev="5.0.0" conf="testCompile-&gt;default"/>
<dependency org="junit" name="junit" rev="4.12" conf="testCompile-&gt;default"/>
</dependencies>
</ivy-module>
2 changes: 1 addition & 1 deletion cyclops-free-monad/repos/ivy-1.0.xml.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56a1e06d07dee9d40b00b60f3abc3e58d0610b7a
e74926d12b736a6b4f223f865aaf3858aebbe7f6
5 changes: 5 additions & 0 deletions cyclops-functions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ modifyPom {
name 'John McClean'
email '[email protected]'
}
developer {
id 'The-Royal-We'
name 'Brendan Carrol'
email '[email protected]'
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=5.0.0
version=5.0.0
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ include ':cyclops-try'
include ':cyclops-tuples'
include ':cyclops-trampoline'
include ':cyclops-free-monad'
include ':cyclops-all'

0 comments on commit 728276d

Please sign in to comment.