Hi Magnus,

the error message is telling you that the `concat` strategy can only flatten 
Sources, not Flows. The `map` combinator in your example just emits Flows but 
does not connect them to the input that you want to pipe through them; in the 
generic, dynamic sense we do not support this currently, you could use groupBy 
to achieve this effect. But your use-case is more static anyway, it should be a 
perfect fit for using the FlexiRoute 
<http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M1/index.html#akka.stream.scaladsl.FlexiRoute>
 junction (see this test suite 
<https://github.com/akka/akka/blob/akka-stream-and-http-experimental-1.0-M1/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlexiRouteSpec.scala>
 for inspiration).

Regards,

Roland

> 6 dec 2014 kl. 16:23 skrev Magnus Andersson <magnus.anders...@mollyware.se>:
> 
> Hi
> 
> I have a flow that I want to conditionally branch off to either one of two 
> other flows. Basically I'm looking to "flatMap that shit", but how do I do 
> this in the context of Akka streams?
> 
> In my current attempt the types will not line up in the flatten step, I get 
> the compile error:
> 
> polymorphic expression cannot be instantiated to expected type;
> [error]  found   : 
> [T]akka.stream.FlattenStrategy[akka.stream.scaladsl.Source[T],T]
> [error]  required: 
> akka.stream.FlattenStrategy[akka.stream.scaladsl.Flow[akka.http.model.HttpRequest,akka.http.model.HttpResponse],?]
> [error]       }.flatten( FlattenStrategy.concat )
> Relevant code:
> 
> val serverBinding = Http( systemRef ).
>   bind(
>     interface = interface,
>     port = port )
> 
> val con: OutgoingConnection = Http( systemRef ).outgoingConnection( "akka.io" 
> )
> 
> val badRequestFlow: Flow[HttpRequest, HttpResponse] =
>   Flow[HttpRequest].map( _ ⇒ HttpResponse( BadRequest, entity = "Bad Request" 
> ) )
> 
> val proxy: Flow[HttpRequest, HttpResponse] = con.flow.concat( Source( () ⇒ 
> List( HttpRequest( GET, uri = "/" ) ).iterator ) )
> 
> val proxyRequest: Flow[HttpRequest, HttpResponse] =
>   Flow[HttpRequest].map {
>     case HttpRequest( POST, Uri.Path( "/proxy" ), _, _, _ ) ⇒ proxy
>     case other ⇒ badRequestFlow
>   }.flatten( FlattenStrategy.concat )
> Any hints or examples warmly welcome! 
> I'm also wondering about supervision of flows (for error handling) but I will 
> put that in a separate post.
> 
> /Magnus
> 
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <https://groups.google.com/group/akka-user>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+unsubscr...@googlegroups.com 
> <mailto:akka-user+unsubscr...@googlegroups.com>.
> To post to this group, send email to akka-user@googlegroups.com 
> <mailto:akka-user@googlegroups.com>.
> Visit this group at http://groups.google.com/group/akka-user 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe <http://typesafe.com/> – Reactive apps on the JVM.
twitter: @rolandkuhn
 <http://twitter.com/#!/rolandkuhn>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to