Skip to content

v9.0.0-MI6 - Higher Kinded functional programming!

Compare
Choose a tag to compare
@johnmcclean johnmcclean released this 07 Jul 14:59
· 88 commits to master since this release

9.0.0-MI6 Release of Cyclops

This simplifies the package structure to make it easier to find the key components

Using Typeclasses (examples for Vavr)

Directly

Typeclasses can be used directly (although this results in verbose and somewhat cumbersome code)
e.g. using the Pure and Functor typeclasses for Vavr Streams

   Pure<stream> pure = Streams.Instances.unit();
   Functor<stream> functor = Streams.Instances.functor();
        
   StreamKind<Integer> stream = pure.unit("hello")
                                  .applyHKT(h->functor.map((String v) ->v.length(), h))
                                  .convert(StreamKind::narrowK);

        
   assertThat(list.toJavaList(),equalTo(Arrays.asList("hello".length())));

Via Active

The Active class represents a Higher Kinded encoding of a Vavr (or cyclops-react/ JDK/ reactor / rx etc) type and it's associated type classes

The code above which creates a new Stream containing a single element "hello" and transforms it to Stream of Integers (the length of each word), can be written much more succintly with Active

Active<stream,Integer> active = Streams.allTypeClasses(Stream.empty());

Active<stream,Integer> hello = active.unit("hello")
                                     .map(String::length);

Stream<Integer> stream = StreamKind.narrow(hello.getActive());

Via Nested

The Nested class represents a Nested data structure, for example a List of Options and the associated typeclass instances for both types.

import cyclops.companion.vavr.Options.OptionNested;

Nested<option,list,Integer> optList  = OptionNested.list(Option.some(List.ofAll(1,10,2,3)))
                                                                       .map(i -> i * 20);

Option<Integer> opt  = optList.foldsUnsafe()
                              .foldLeft(Monoids.intMax)
                              .convert(OptionKind::narrowK);


//[200]

Via Coproduct

Coproduct is a Sum type for HKT encoded types that also stores the associated type classes

import static 
Coproduct<list,option,Integer> nums = Options.coproduct(10,Lists.Instances.definitions());


int value = nums.map(i->i*2)
                .foldUnsafe()
                .foldLeft(0,(a,b)->a+b);

//20

Getting Cyclops 9.0.0-MI6

MODULE_NAMES : cyclops-scala, cyclops-clojure, cyclops-dexx, cyclops-rx, cyclops-reactor, cyclops-guava, cyclops-functionaljava, cyclops-vavr, cyclops-rxjava2

Gradle

       compile 'com.aol.cyclops:MODULE_NAME:9.0.0-MI6’

Maven

     <dependency>
           <groupId>com.aol.cyclops</groupId>
           <artifactId>MODULE_NAME</artifactId>
           <version>9.0.0-MI6</version>
     </dependency>

Javadoc

http://www.javadoc.io/doc/com.aol.cyclops/cyclops-scala/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-clojure/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-dexx/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-rx/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-rxjava2/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-reactor/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-vavr/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-functionaljava/9.0.0-MI6
http://www.javadoc.io/doc/com.aol.cyclops/cyclops-guava/9.0.0-MI6