Skip to content

Commit

Permalink
Merge abf3ba3 into 521822f
Browse files Browse the repository at this point in the history
  • Loading branch information
jponge authored Sep 15, 2023
2 parents 521822f + abf3ba3 commit 71c7c11
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye.reactive:mutiny:2.4.0
package _07_advanced_streaming;

import static _07_advanced_streaming._01_Multi_Split.Country.*;

import java.util.List;

import io.smallrye.mutiny.Multi;

public class _01_Multi_Split {

static class TemperatureRecord {
final Country country;
final String city;
final long timestamp;
final double value;

TemperatureRecord(Country country, String city, long timestamp, double value) {
this.country = country;
this.city = city;
this.timestamp = timestamp;
this.value = value;
}

@Override
public String toString() {
return "TemperatureRecord{" +
"country=" + country +
", city='" + city + '\'' +
", timestamp=" + timestamp +
", value=" + value +
'}';
}
}

enum Country {
FRANCE,
UK,
AUSTRALIA
}

public static void main(String[] args) {
System.out.println("⚡️ Multi split operator");

var data = List.of(
new TemperatureRecord(FRANCE, "Tassin-La-Demi-Lune", System.nanoTime(), 28.0),
new TemperatureRecord(FRANCE, "Clermont-Ferrand", System.nanoTime(), 27.0),
new TemperatureRecord(FRANCE, "Nevers", System.nanoTime(), 27.0),
new TemperatureRecord(FRANCE, "Aubière", System.nanoTime(), 28.0),
new TemperatureRecord(AUSTRALIA, "Sydney", System.nanoTime(), 16.0),
new TemperatureRecord(FRANCE, "Lyon", System.nanoTime(), 29.0),
new TemperatureRecord(AUSTRALIA, "Kensington", System.nanoTime(), 16.0),
new TemperatureRecord(UK, "Newcastle", System.nanoTime(), 13.0),
new TemperatureRecord(AUSTRALIA, "Coogee", System.nanoTime(), 16.0),
new TemperatureRecord(UK, "Bexhill", System.nanoTime(), 22.0));

var splitter = Multi.createFrom().iterable(data)
.split(Country.class, record -> record.country);

splitter.get(FRANCE)
.subscribe().with(
record -> System.out.println("🇫🇷 => " + record),
Throwable::printStackTrace,
() -> System.out.println("✅ Done with France"));

splitter.get(AUSTRALIA)
.subscribe().with(
record -> System.out.println("🇦🇺🦘 => " + record),
Throwable::printStackTrace,
() -> System.out.println("✅ Done with Australia"));

splitter.get(UK)
.subscribe().with(
record -> System.out.println("🇬🇧 => " + record),
Throwable::printStackTrace,
() -> System.out.println("✅ Done with the UK"));

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye.reactive:mutiny:2.4.0
package _07_misc;
package _08_misc;

import java.util.concurrent.ThreadLocalRandom;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye.reactive:mutiny:2.4.0
package _07_misc;
package _08_misc;

import io.smallrye.mutiny.Multi;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye.reactive:mutiny:2.4.0
package _07_misc;
package _08_misc;

import java.util.List;

Expand Down

0 comments on commit 71c7c11

Please sign in to comment.