Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kleisli work in progress. #510

Merged
merged 14 commits into from
Feb 15, 2017
Empty file removed There
Empty file.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 2.0.0-MI3
version = 2.0.0-MI4
lombokVersion=1.16.12
joolVersion=0.9.12
pCollectionsVersion=2.1.2
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 @@ -14,7 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* along with this program; if not, tell to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,7 @@ public <U> LazyListX<U> unitIterator(Iterator<U> it) {
}


public static void main(String[] args){

ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
stream.map(i->i*2).printOut();
ReactiveSeq<Integer> r2 = stream.map(i->i*2);
r2.map(i->i*100).zipWithIndex().printOut();
r2.map(i->i*1000).zipWithIndex().printOut();
/**
LazyListX<Integer> l2 = new LazyListX<>(null,ReactiveSeq.of(1,2,3), Collectors.toList());
l2.map(i->i*100).printOut();
l2.map(i->i*1000).printOut();
**/
/**
// LazyListX<Integer> list = new LazyListX<>(null,ReactiveSeq.of(1,2,3), Collectors.toList());
LazyListX<Integer> list = new LazyListX<>(Arrays.asList(1,2,3),null, Collectors.toList());

list.map(i->i*2).printOut();
ListX<Integer> l2 = list.map(i->i*2);
System.out.println(l2.getClass());
list.map(i->i*3)
.peek(System.out::println)
.forEach(System.err::println);

l2.map(i->i*100).printOut();
System.out.println(l2.getClass() + " " + ((LazyListX)l2).getList());
l2.map(i->i*1000).printOut();
**/
}


@Override
public <R> LazyListX<R> unit(Collection<R> col) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.aol.cyclops2.data.collections.extensions.lazy.immutable;


import com.aol.cyclops2.data.collections.extensions.persistent.PersistentCollectionX;
import cyclops.Reducers;
import cyclops.collections.immutable.PBagX;
import cyclops.function.Reducer;
import cyclops.stream.ReactiveSeq;
import org.pcollections.PBag;

Expand Down Expand Up @@ -47,6 +47,11 @@ public LazyPBagX(PBag<T> list, ReactiveSeq<T> seq) {
super(list, seq, Reducers.toPBag());


}
public LazyPBagX(PBag<T> list, ReactiveSeq<T> seq, Reducer<PBag<T>> reducer) {
super(list, seq, reducer);


}
public LazyPBagX(PBag<T> list) {
super(list, null, Reducers.toPBag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import cyclops.Reducers;
import cyclops.collections.immutable.PBagX;
import cyclops.collections.immutable.POrderedSetX;
import cyclops.function.Reducer;
import cyclops.stream.ReactiveSeq;
import org.pcollections.POrderedSet;

Expand Down Expand Up @@ -47,6 +47,11 @@ public LazyPOrderedSetX(POrderedSet<T> list, ReactiveSeq<T> seq) {
super(list, seq, Reducers.toPOrderedSet());


}
public LazyPOrderedSetX(POrderedSet<T> list, ReactiveSeq<T> seq, Reducer<POrderedSet<T>> reducer) {
super(list, seq, reducer);


}
public LazyPOrderedSetX(POrderedSet<T> list) {
super(list, null, Reducers.toPOrderedSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import cyclops.Reducers;
import cyclops.collections.immutable.PBagX;
import cyclops.collections.immutable.PQueueX;
import cyclops.function.Reducer;
import cyclops.stream.ReactiveSeq;
import org.pcollections.PQueue;

Expand Down Expand Up @@ -47,6 +47,11 @@ public LazyPQueueX(PQueue<T> list, ReactiveSeq<T> seq) {
super(list, seq, Reducers.toPQueue());


}
public LazyPQueueX(PQueue<T> list, ReactiveSeq<T> seq, Reducer<PQueue<T>> reducer) {
super(list, seq, reducer);


}
public LazyPQueueX(PQueue<T> list) {
super(list, null, Reducers.toPQueue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import cyclops.Reducers;
import cyclops.collections.immutable.PBagX;
import cyclops.collections.immutable.PSetX;
import cyclops.function.Reducer;
import cyclops.stream.ReactiveSeq;
import org.pcollections.PSet;

Expand Down Expand Up @@ -47,6 +47,11 @@ public LazyPSetX(PSet<T> list, ReactiveSeq<T> seq) {
super(list, seq, Reducers.toPSet());


}
public LazyPSetX(PSet<T> list, ReactiveSeq<T> seq, Reducer<PSet<T>> reducer) {
super(list, seq, reducer);


}
public LazyPSetX(PSet<T> list) {
super(list, null, Reducers.toPSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import cyclops.Reducers;
import cyclops.collections.immutable.PBagX;
import cyclops.collections.immutable.PStackX;
import cyclops.function.Reducer;
import cyclops.stream.ReactiveSeq;
import lombok.Getter;
import org.pcollections.PStack;
Expand Down Expand Up @@ -51,6 +51,11 @@ public LazyPStackX(PStack<T> list, ReactiveSeq<T> seq, boolean efficientOps) {
super(list, seq, Reducers.toPStack());
this.efficientOps= efficientOps;

}
public LazyPStackX(PStack<T> list, ReactiveSeq<T> seq, boolean efficientOps, Reducer<PStack<T>> reducer) {
super(list, seq, reducer);
this.efficientOps= efficientOps;

}
public LazyPStackX(PStack<T> list,boolean efficientOps) {
super(list, null, Reducers.toPStack());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import cyclops.Reducers;
import cyclops.collections.immutable.PBagX;
import cyclops.collections.immutable.PVectorX;
import cyclops.function.Reducer;
import cyclops.stream.ReactiveSeq;
import org.pcollections.PVector;

Expand Down Expand Up @@ -45,6 +45,9 @@ public LazyPVectorX(PVector<T> list, ReactiveSeq<T> seq) {
super(list, seq, Reducers.toPVector());


}
public LazyPVectorX(PVector<T> list, ReactiveSeq<T> seq, Reducer<PVector<T>> reducer) {
super(list, seq, reducer);
}
public LazyPVectorX(PVector<T> list) {
super(list, null, Reducers.toPVector());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ public Topic<T> broadcast(){

if(wip.compareAndSet(false,true)){
try {
//use the first consuming thread to write this Stream onto the Queue
//use the first consuming thread to tell this Stream onto the Queue
s.request(1000-queue.size());
}finally {
wip.set(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Created by johnmcclean on 22/12/2016.
*/

public class IteratableSpliterator<T> extends Spliterators.AbstractSpliterator<T> implements CopyableSpliterator<T>, Printable {
public class IteratableSpliterator<T> extends Spliterators.AbstractSpliterator<T> implements CopyableSpliterator<T>{

private final Iterable<T> source;

Expand Down Expand Up @@ -40,7 +40,7 @@ public boolean tryAdvance(Consumer<? super T> action) {
if(active==null)
active=source.iterator();
if (active.hasNext()) {
action.accept(print(active.next()));
action.accept(active.next());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Created by johnmcclean on 12/01/2017.
*/
@AllArgsConstructor
public class ZippingOperator<T1,T2,R> implements Operator<R>, Printable {
public class ZippingOperator<T1,T2,R> implements Operator<R>{


Operator<? super T1> left;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/aol/cyclops2/types/Folds.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ default String join(final String sep, final String start, final String end) {
/**
* Write each element within this Folds in turn to the supplied PrintStream
*
* @param str PrintStream to write to
* @param str PrintStream to tell to
*/
default void print(final PrintStream str) {
stream().print(str);
Expand All @@ -338,7 +338,7 @@ default void print(final PrintStream str) {
/**
* Write each element within this Folds in turn to the supplied PrintWriter
*
* @param writer PrintWriter to write to
* @param writer PrintWriter to tell to
*/
default void print(final PrintWriter writer) {
stream().print(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,20 @@ default <T> Stream<CompletableFuture<T>> streamCompletableFutures() {
* <pre>
* {@code
* List<String> result = SimpleReactStream.of(1,2,3)
* .merge(FutureStream.of(100,200,300))
* .product(FutureStream.of(100,200,300))
.map(it ->it+"!!")
.toList();
assertThat(result,equalTo(Arrays.asList("1!!","2!!","3!!","100!!","200!!","300!!")));
*
* }
* </pre>
*
* @param s Stream to merge
* @param s Stream to product
*
* @return Next stage in reactiveStream
*
* @see
* com.aol.simple.react.reactiveStream.traits.FutureStream#merge(com.aol.simple.
* com.aol.simple.react.reactiveStream.traits.FutureStream#product(com.aol.simple.
* react.reactiveStream.traits.SimpleReactStream)
*/

Expand Down
55 changes: 50 additions & 5 deletions src/main/java/cyclops/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import com.aol.cyclops2.types.Unit;
import cyclops.collections.ListX;
import cyclops.control.Maybe;
import cyclops.function.Fn1;
import cyclops.function.Monoid;
import cyclops.function.*;
import cyclops.monads.AnyM;
import cyclops.monads.Witness;
import cyclops.monads.WitnessType;
import cyclops.stream.ReactiveSeq;
import cyclops.typeclasses.monad.Monad;

import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;

/**
* Collection of useful functions
Expand All @@ -27,7 +27,7 @@
* {@link cyclops.function.PartialApplicator}
* {@link cyclops.function.Memoize}
* {@link cyclops.function.FluentFunctions}
* {@link Fn1}F
* {@link Fn1}
* {@link Fn2}
* {@link Fn3}
* {@link Fn4}
Expand Down Expand Up @@ -102,4 +102,49 @@ public static final <T> Fn1<? super Iterable<T>,? extends T> reduce(Monoid<T> m
.reduce(monoid.zero(),monoid);
}

static <K,V> Fn1<K,V> map(Map<K,V> map) {
return map::get;
}
static <K,V> Fn1<K,Maybe<V>> maybeMap(Map<K,V> map) {
return k->Maybe.ofNullable(map.get(k));
}
static <K,V> Fn1<K,Optional<V>> optionalMap(Map<K,V> map) {
return k-> Optional.ofNullable(map.get(k));
}

static <T,R,R1, R2, R3, R4> Function<T,R4> forEach4(Function<? super T, ? extends R> fn,
Function<? super R, Function<? super T,? extends R1>> value2,
BiFunction<? super R, ? super R1, Function<? super T,? extends R2>> value3,
Fn3<? super R, ? super R1, ? super R2, Function<? super T,? extends R3>> value4,
Fn4<? super R, ? super R1, ? super R2, ? super R3, ? extends R4> yieldingFunction) {

Reader< T,R> rd = Reader.narrow(FluentFunctions.of(fn));
return rd.forEach4(value2, value3, value4, yieldingFunction);



}

static <T,R,R1, R2, R4> Function<T,R4> forEach3(Function<? super T, ? extends R> fn,
Function<? super R, Function<? super T,? extends R1>> value2,
BiFunction<? super R, ? super R1, Function<? super T,? extends R2>> value3,
Fn3<? super R, ? super R1, ? super R2, ? extends R4> yieldingFunction) {


Reader< T,R> rd = Reader.narrow(FluentFunctions.of(fn));
return rd.forEach3(value2, value3, yieldingFunction);
}



static <T,R,R1, R4> Function<T,R4> forEach2(Function<? super T, ? extends R> fn,
Function<? super R, Function<? super T,? extends R1>> value2,
BiFunction<? super R, ? super R1, ? extends R4> yieldingFunction) {

Reader< T,R> rd = Reader.narrow(FluentFunctions.of(fn));
return rd.forEach2(value2, yieldingFunction);


}

}
Loading