Comments (11)
I'd be very happy to see that actually. Seen such patterns in big data things before but noone had a nice api for it.
Interesting idea would be:
Source.single("name" -> 42)
.focusOn(_._2)
.map(_ + 58) // could these be SubFlow/Source?
.filter(_ > 10) // could these be SubFlow/Source?
.unfocus
.map { case (name, num) => s"$name -> $num" }
from akka-stream-contrib.
I'll upload the code and open a PR later, so you can have a look.
The focus/unfocus looks nice, but I'm not sure how it would work. Where will it keep the "current" ID?
The current API looks like this:
val innerFlow = Flow[String].map(_.toUpperCase).filterNot(s => s.startsWith("T"))
val foo = Source(List((1l, "one"), (2l, "two"), (3l, "three"), (4l, "four")))
.via(enrich(innerFlow))
.runWith(Sink.foreach(println))
from akka-stream-contrib.
Perhaps exact syntax of focusOn is unachievable, but I think the feature should be possible.
Effectively .map(el => f(ef))
is actually .map(el => copy(f(extract(ef)))
.
We need the copy
and extract
implemented. Extract is trivial, it's just _._2
, copy may be something we ask people to provide in focusOn
, so (t, s) => t.copy(bla = s)
.
It would be fun to see if we could use techniques from lenses here, see: https://github.com/julien-truffaut/Monocle
from akka-stream-contrib.
Ooh, good idea. I'll try to see if I can make it work.
(Just to be clear, you don't mean to actually use Monocle/catz/whatever, right?)
from akka-stream-contrib.
We could, if it turns out to be awesome might be very fun project.
Could live as separate project in akka-stream-contrib.
Simple one would be nice anyway, and perhaps then the more generic monocle-powered version
from akka-stream-contrib.
Issues are many-to-many Flows (this have been considered before). It might work in some cases but be aware of the issue.
from akka-stream-contrib.
@ktoso
Here's the initial code I had: http://pastebin.com/CNx30ic9
I'll do some more work trying to get the "focus/unfocus" API (the current approach I'm trying is to extend FlowOpsMat...), and then tidy things up and upload to GH.
@drewhk
Yeah, I know. If it ends up here, that will have to be documented properly. Still, even in its current form it's pretty useful (to me, at least).
from akka-stream-contrib.
@ktoso
I pushed the code to: https://github.com/talpr/akka-stream-contrib/commits/talpr-50-flow-tagger
I got focus/unfocus to work, but without support for materialized values (inner flow is always materialized to NotUsed). The latest commit in the branch(77a8f63) is the one without materialization, the commit before that(14e4fa7) is my initial attempt to handle materialization.
The problem is that while the inner flow is being constructed, the original source/flow is not yet connected to the inner flow, so I couldn't get the types (and semantics) to line up. It's probably possible by making a new shape, and then importing the source/flow into it, but I'll have to fiddle with it some more and see where I get.
What do you think?
from akka-stream-contrib.
Cool! Could you submit that branch as a PR? It's easier to comment and check out this way :)
from akka-stream-contrib.
@ktoso
I got materialized values to work. Not the prettiest thing in the world, but it works...
(PR #52)
from akka-stream-contrib.
More discussion that may be relevant: akka/akka#15957
from akka-stream-contrib.
Related Issues (20)
- Make the valve state inspection always complete
- Alternative way of defining Graph Stages HOT 3
- Release 0.9 HOT 1
- IntervalBasedRateLimiter should limit rate of messages when frequency is very high (50 000 elements per 1 000ms) failed: 4 was not equal to 3
- FileTailSource and DirectoryChanges have moved to Alpakka HOT 1
- replace scala.Either in PartitionWith Java API HOT 3
- Any interest in integrating actor into a Flow though a GraphStage? HOT 3
- Add maxNumber and maxTime to AccumulateWhileUnchanged
- Publish artifacts for scala 2.13 HOT 2
- Publishing from Travis fails
- Remove unrelated tools
- PassThroughFlow limits the rate of the inner processingFlow HOT 5
- Remove PassThroughFlow which is not superseded by FlowWithContext
- Introduce Token Throttle HOT 3
- TokenThrottle can fail to complete and doesn't consistently pre-fetch tokens
- Publish API documentation to doc.akka.io HOT 7
- Support for sorting fan-in shape with more than two upstreams
- Migrate from travis.org to travis.com HOT 1
- Shared valve switch HOT 1
- Why no more releases? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from akka-stream-contrib.