v7.1.0 of Cyclops : Streams - Scheduling & for-comprehensions, singleOptional operator, new monad transformers, Mutable enhancements
7.1.0 Release of Cyclops
Stream enhandements
Scheduling Streams
Run a job every minute and log to the db once per day.
SequenceM.generate( () -> "new job")
.map(this::process)
.schedule("0 * * * * ?", ex)
.connect()
.debounce(1,TimeUnit.DAYS)
.forEach(this::logToDb);
Available as a static method in StreamUtils for JDK and java slang Streams
Stream for-comprehensions
Nested loops over multiple Streams
SequenceM.of(1,2,3)
.forEach2(a->IntStream.range(0,10),
a->b-> a+b)
.toList()
//List[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)]
With the (optional) ability to filter
SequenceM.of(2,3)
.forEach3(a->IntStream.range(6,9),
a->b->IntStream.range(100,105),
a->b->c -> a==3,
a->b->c-> a+b+c)
//List[109, 110, 111, 112, 113, 110, 111, 112, 113, 114, 111, 112, 113, 114, 115]
Or use any monad type (via AnyM)
AnyM.streamOf(1,null,2,null,3)
.forEach2(a->AnyM.<Integer>fromOptional(Optional.ofNullable(a)),
a->b-> a+b)
//AnyM[Stream[1,2,3]]
singleOptional operator
//Optional[1]
SequenceM.of(1).singleOptional();
//Optional.empty
SequenceM.of().singleOpional();
//Optional.empty
SequenceM.of(1,2,3).singleOptional();
New Mutable methods and types
Mutable provides an API for encapsulated, or external, mutable values, for example, for mutating local variables inside Lambda Expressions.
New Mutable types
- MutableBoolean
- MutableByte
- MutableShort
- MutableFloat
- MutableChar
- MutableShort
Mutable<String> var = Mutable.of("hello");
Runnable r = () -> var.set("world");
String value = "world";
Mutable<String> ext = Mutable.fromExternal(()->value,v->this.value=v);
ext.set("hello");
MutableFloat myFloat = new MutableFloat(zero);
Function<Integer,Function<Integer,MutableFloat>> fn = ((Integer i)-> (Integer j)-> myFloatset(new Float((float)(i*j))));
fn.apply(10).apply(20);
//myFloat 200
Mutable<String> ext = Mutable.fromExternal(()->value,v->this.value=v)
.mapInput(s->s+"!");
ext.set("hello");
//value == "hello!"
New Monad Transformers
- TryT
- SetT
javadoc added for
- OptionalT
- StreamT
- StreamableT
- ListT
- CompletableFutureT
Function<Integer,Integer> add2 = i -> i+2;
Function<OptionalT<Integer>, OptionalT<Integer>> optTAdd2 = OptionalT.lift(add2);
Stream<Integer> withNulls = Stream.of(1,2,null);
AnyM<Integer> stream = AnyM.ofMonad(withNulls);
AnyM<Optional<Integer>> streamOpt = stream.map(Optional::ofNullable);
List<Integer> results = unwrapOptional(optTAdd2.apply(OptionalT.of(streamOpt)))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
//List(3,4);
New convertable mixin
Convertable.fromSupplier(()->null).orElse(11)
//11
Convertable.fromSupplier(()->10).toAtomicReference()
//AtomicReference[10]
Convertable.fromSupplier(()->10).toList()
//List(10)
etc.
Feature Tracking
- cyclops-monad-api :SetT monad transformer
- cyclops-streams : HotStream closes connected Streams when transfer queue is empty
- cyclops-streams : Debounce returns last value in stream even if a value already sent for this time period
- TryT monad transformer
- cyclops-monad-api : Correctly handling primitive Streams
- cyclops-closures : Allow mutable to lazily modify / map inputs and outputs
- cyclops-invokde-dynamic : ExceptionSoftener add softenCallable method
- cyclops-closures : Add a Convertable mixin that allows a Supplier to be converted into a Stream, Optional, List, CompletableFuture, AtomicReference etc
- cyclops-moad-api : javadoc monad transformers
- Create primitive versions of Mutable
- cyclops-streams :- add scheduling capabilities for HotStreams
- cyclops-monad-api : New AnyM operators for-comprehensions
- cyclops-streams : singleOptional operator for SequenceM
- cyclops-streams : for-comprehension operators for SequenceM
- cyclops-streams : add scheduling operators to StreamUtils
- cyclops-javaslang : add scheduling for Javaslang Streams to Javaslang - StreamUtils
- cyclops-streams : HotStream closes connected Streams when transfer queue is empty
Getting Cyclops 7.1.0
cyclops-all has all non-integration modules, but each module can be used / added individually (subject to it's own dependencies). Instructions for each module are in it's own readme.md.
Gradle
compile 'com.aol.cyclops:cyclops-all:7.1.0'
Maven
<dependency>
<groupId>com.aol.cyclops</groupId>
<artifactId>cyclops-all</artifactId>
<version>7.1.0</version>
</dependency>
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-sequence-api/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-streams/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-monad-api/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-monad-functions/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-mixins/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-invokedynamic/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-for-comprehensions/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-functions/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-try/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/pattern-matching/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-trampoline/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-feature-toggle/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-core/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-tuples/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-all/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-javaslang/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-functionaljava/7.1.0
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-guava/7.1.0