JOOL: combinatorial stream

15 views
Skip to first unread message

tdud...@informaticsmatters.com

unread,
Mar 14, 2015, 4:41:51 AM3/14/15
to jooq...@googlegroups.com
I hope this is the place to ask about JOOL. Appologies if not.
I need to be able to combine multiple streams in a combinatorial manner.
e.g. I have n streams (n would normally be 2 or 3) and I want to generate a single stream that contains every combination of elements in each of those streams.
Looking at JOOL it seems that Seq.duplicate() and Seq.intersperse() may be useful in handling this, but I'm not sure how to go about this.
Essentially I'm looking for something that looks a bit like this:

Stream<Tuple> combine(Stream... streams)

Just to be clear, if I had 2 streams, A and B that had these values:

A: X,Y,Z
B: 6,7,8

I would get a single stream that contains:

(X,6), (X,7), (X,8), (Y,6), (Y,7), (Y,8), (Z,6), (Z,7), (Z,8)

Note: the streams do not need to be the same size, you just get A * B (or A *B * C ...) elements in the resulting stream.

Many thanks for any advice on this.

Tim

Lukas Eder

unread,
Mar 14, 2015, 5:11:52 AM3/14/15
to jooq...@googlegroups.com
Hello

2015-03-13 20:18 GMT+01:00 <tdud...@informaticsmatters.com>:
I hope this is the place to ask about JOOL. Appologies if not.

Yes, it's OK. Otherwise, a GitHub feature request might work as well:
 
I need to be able to combine multiple streams in a combinatorial manner.
e.g. I have n streams (n would normally be 2 or 3) and I want to generate a single stream that contains every combination of elements in each of those streams.
Looking at JOOL it seems that Seq.duplicate() and Seq.intersperse() may be useful in handling this, but I'm not sure how to go about this.
Essentially I'm looking for something that looks a bit like this:

Stream<Tuple> combine(Stream... streams)

Just to be clear, if I had 2 streams, A and B that had these values:

A: X,Y,Z
B: 6,7,8

I would get a single stream that contains:

(X,6), (X,7), (X,8), (Y,6), (Y,7), (Y,8), (Z,6), (Z,7), (Z,8)

Note: the streams do not need to be the same size, you just get A * B (or A *B * C ...) elements in the resulting stream.

Hmm, that would be a cartesian product or cross product of A x B:

I'm sure you know what you're doing. As a SQL guy talking to DBA all the time, this is kind of a poisonous topic ;-)

Right now, jOOL doesn't help you do that, but there is a lot of talk about the topic when in combination with Scala. E.g.:

We'd happily merge a contribution if you want to give an implementation a shot...

Cheers
Lukas
Reply all
Reply to author
Forward
0 new messages