Introducing Cyclops X

John McClean
4 min readNov 5, 2017

We are planning big improvements for cyclops over the coming months, starting with the release of Cyclops 10 (Cyclops X).

We intended to rename the core library from cyclops-react to just cyclops, with this in place we can also unify the versioning across the core and the add-on libraries — hence across both cyclops-react and the cyclops integration modules the next version will be 10 (or Cyclops X). With the merger of Aol and Yahoo to form Oath, package names will change from com.aol.cyclops to com.oath.cyclops and Cyclops X will be released on a com.oath.cyclops group id.

All new, fast purely functional data structures

A big enhancement is the introduction of a suite of all new purely functional data types.

Functional Data Structures in Cyclops X

Pattern Matching and Algebraic Data Types

cyclops X will introduce a new much improved, type-safe pattern matching API (with annotation processor) written by Max Chiareli Xandeco.

At the same time we will also introduce a range of common purely functional algebraic data types (including LinkedList, Bitmapped Array Trie backed Vector, HashMap, HashSet, Discrete Interval Encoded Tree, DifferenceList, HList, DependentMap, MultiMap,NonEmptyList, LazyList and more). These data types will be stricter than most currently avaiable JVM implementations and will restrict potential runtime errors by leveraging the pattern mathing API to ensure that users can only access operations that will work — it won’t be possible to attempt to extract data from an empty list for example.

Safe APIs

Over the last 12 months releases have focused on incrementally improving type safety in cyclops. Cyclops X will remove a lot of unsafe APIs from the core. The get method on Value types will disappear, so unlike in the JDK’s Optional class Cyclops X’s Option will not support a direct get Operation

Option<Integer> opt = Option.none();
opt.get(); // ERROR! -> not possible

We can make use of Pattern Matching to safely extract the data

or the orElse methods that allow us to specify a default value.

Right through out the library potentially unsafe APIs have been removed and the new data types do not support operations that may result in exceptional states.

In our ImmutableList types (such as Vector, Seq, LazySeq, IntMap, NonEmptyList) it is not possible to execute operations that would result in exceptional states (such as IndexOutOfBoundsExceptions).

Modularization

Another major theme of cyclops X is the introduction of a suite of finer grained modules. This will benefit developers by making it easier to find functionality you need from cyclops without having to import the whole (large) project.

The first Cyclops-X modules will be released as part of Milestone 2, however all of the functionality is already available today within Cyclops X Milestone 1.

Eager and Lazy Data Types

In some cases data types that execute lazily can be more performant than their eager analogues. In others, the (generally lower) storage overheads and complexity of the eager type will be more beneficially for an application. In Cyclops X, we do our best to provide application developers a choice between performant eager and lazy analogues. For example our Maybe type is lazy, much like it’s Haskell namesake — it behaves in practice like a Stream of 0 /1 values. Option, on the other hand, like it’s Scala namesake is eager.

some of the eager and lazy analogues in cyclops X

Milestone one of Cyclops X is available now

Cyclops X will be released in stages over the next 8–10 months, and the first milestone is available on Maven Central today. Do checkout the release notes for cyclops X milestone one , and also do note that we have changed our group id from com.aol.simplereact to ->com.oath.cyclops.

Over the coming weeks and months I hope to show you how to use the new features and data structures in Cyclops X to write safe, testable, performant code.

--

--

John McClean

Architecture @ Verizon Media. Maintainer of Cyclops. Twitter @johnmcclean_ie