Skip to content

Mixins : ValueObject

johnmcclean-aol edited this page May 31, 2015 · 2 revisions

The ValueObject Interface

Implementing com.aol.cyclops.value.ValueObject in cyclops-core adds both Pattern Matching support and decomposition support to any object. It combines the Matchable interface and the Decomposable interface.

Coercing to ValueObject

Any Object can be coerced to a ValueObject via the following methods

  • AsValue.asValue
  • As.asValue

Example : _match

With Lombok @Value

int result = As.asValue(new Child(10,20))._match(c->  
                   c.isType( (Child child) -> child.value).with(__,20)));


//result is 20 (child.value)
@Value static class Child { int num,int value }
Clone this wiki locally