Page History
...
Code Block | ||||
---|---|---|---|---|
| ||||
// Create a source from an Iterable Source.From(new List<int> {1, 2, 3}); // Create a source from a Task Source.FromTask(Task.FromResult("Hello Streams!")); // Create a source from a single element Source.Single("only one element") // an empty source Source.Empty<int>(); // Sink that aggregates over the stream and returns a Task // of the final result as its materialized value Sink.Aggregate<int, int>(0, (sum, i) => sum + i); // Sink that returns a Task as its materialized value, // containing the first element of the stream Sink.First<int>(); // A Sink that consumes a stream without doing anything with the elements Sink.Ignore<int>(); // A Sink that executes a side-effecting call for every element of the stream Sink.ForEach<string>(Console.WriteLine); |
흐름처리를 조금더 명시화한 스트림처리
Code Block | ||||
---|---|---|---|---|
| ||||
actorSystem = ActorSystem.Create("ServiceB");
materializer = actorSystem.Materializer();
var flow = Flow.Create<int>().Select(x => x * 2);
var flow2 = Flow.Create<int>().Select(x => x + 3);
var runnablegraph = Source.From(Enumerable.Range(1, 10))
.Via(flow) //Via는 Source와 Flow를 결합하여 Source로 만듭니다.
.Via(flow2) //Via의 결과값이 Source이기때문에 다시 Flow와 조합이 가능
.Where(x => x > 10 ) //Filter조건으로 10이하의 값은 버린다.
.To( Sink.ForEach<int>(x => Console.WriteLine(x.ToString())) );
runnablegraph.Run(materializer); |