My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

"Without an observer, the world observed doesn't really exist either." - 101 Sci-fi stories

Current version: 0.96 Java

2012-01-26 10:30:00 CET, JavaDoc, Release Notes, Install Notes

Introduction

The library features composable operators for typical collection-like management tasks for both reactive (e.g., Observable) and interactive (Iterable) scenarios:

  • select
  • selectMany
  • where
  • concat
  • distinct
  • groupBy
  • etc.

Requirements

  • Java 6 or later
  • JSR 305 annotation library (download jsr305.jar from this project or from original place)
  • GWT 2.2.0 or later (might work with earlier verison, have not tried)

Plans

  • Add a dataflow extension similar to the TPL Dataflow library
  • Add some remaining operators
  • Finish documentation

The future

Running some searches against this project hints some dark future. It appears only when I basically type in everything - zero visibility. Probably some big-name company will someday create a similar implementation which will render my little project nil.

Examples

Interactive

// return a single element
IterableBuilder.from(1).print();
// return a range
IterableBuilder.range(0, 10).print();
// combine two iterables
IterableBuilder.from(0).concat(IterableBuilder.range(1, 9)).print();
// return multiple things for a single thing

IterableBuilder.range(0, 10).selectMany(
new Func1<Integer, Iterable<Integer>>() {
	@Override
	public Iterable<Integer> invoke(Integer param) {
		return Interactive.range(0, param + 1);
	}
}).print();

// classic query
IterableBuilder.range(0, 10)
.where(new Pred1<Integer>() {
	@Override
	public Boolean invoke(Integer param1) {
		return param1 % 2 == 0;
	} })
.select(new Func1<Integer, Integer>() {
	@Override
	public Integer invoke(Integer param1) {
		return param1 * param1;
	} })
.print();

// lambda functions via scripting
IterableBuilder.range(0, 10).where(
		Lambdas.<Integer, Boolean>js1("o => o % 2 == 0"))
		.print();

Reactive

// return a single element
ObservableBuilder.from(1).print();
// return a range
ObservableBuilder.range(0, 10).print();
// combine two iterables
ObservableBuilder.from(0).concat(ObservableBuilder.range(1, 9)).print();
// return multiple things for a single thing

ObservableBuilder.range(0, 10).selectMany(
new Func1<Integer, ObservableBuilder<Integer>>() {
	@Override
	public ObservableBuilder<Integer> invoke(Integer param) {
		return ObservableBuilder.range(0, param + 1);
	}
}).print();

// classic query
ObservableBuilder.range(0, 10)
.where(new Pred1<Integer>() {
	@Override
	public Boolean invoke(Integer param1) {
		return param1 % 2 == 0;
	} })
.select(new Func1<Integer, Integer>() {
	@Override
	public Integer invoke(Integer param1) {
		return param1 * param1;
	} })
.print();

// lambda functions via scripting
ObservableBuilder.range(0, 10).where(
		Lambdas.<Integer, Boolean>js1("o => o % 2 == 0"))
		.print();

Older examples

Notes

Key things to note:

  • Without lambdas in Java, writing the library is ugly, using the library is ugly
  • Disposability interpretation
  • The API naming is subject to change, especially the utility methods of Observables.

Suggestions are welcome (e.g. what kind of operator to include, what kind of helper methods to introduce, etc.).

About me: I'm (still) a PhD student specializing in production informatics related topics, mainly in the transparency-related issues of discrete part manufacturing, assembly and logistics.

You might have heard about the Rx (Reactive Extensions) of C# and JavaScript. It represents the dual to Iterables and Iterators and allows nice compositions and asynchronous processings.

I participate in an EU sponsored research project called Advance (http://www.advance-logistics.eu) which will need an abstract data-flow based engine. Due to the requirements, a reactive framework such as Rx would do nicely as a basis for this engine. Unfortunately, Java doesn't have one and noone seems to port/create one.

I won't deny, the library got a great deal of inspiration from Rx, and from http://blogs.bartdesmet.net/blogs/bart/archive/2010/01/01/the-essence-of-linq-minlinq.aspx , but the Rx documentation is a bit vague about some semantical details, especially the scheduling dimension of the observable stuff and how disposition-composition should work.

Powered by Google Project Hosting