Skip to content

Mixins : StreamableValue

johnmcclean-aol edited this page Feb 24, 2016 · 3 revisions

Cyclops has merged with simple-react. Please update your bookmarks (stars :) ) to https://github.com/aol/cyclops-react

All new develpoment on cyclops occurs in cyclops-react. Older modules are still available in maven central.

screen shot 2016-02-22 at 8 44 42 pm

The StreamableValue Interface

Implementing com.aol.cyclops.value.StreamableValue in cyclops-core extends the ValueObject interface and adds Streamable support and support for For Comprehensions.

Coercing to StreamableValue

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

  • AsStreamableValue.asStreamableValue
  • As.asStreamableValue

Example : do

With Lombok @Value

     Stream<Double> withBonus = As.<Double>asStreamableValue(new BaseData(10.00,5.00,100.30))
				     .doWithThisAnd(d->asList(2.0))
			             .yield((Double base)->(Double bonus)-> base*(1.0+bonus));
	
	
	
  double total = withBonus.collect(Collectors.summingDouble(t->t));
	
  assertThat(total,equalTo(345.9));

    @Value static class BaseData{ double salary; double pension; double socialClub; }
Clone this wiki locally