I did something similar but a bit a bit more generic: EitherJunction[I, L, R
](f: I => Either[L, R]) [1] that can handle outlets of different types.
I needed that to implement HTTP redirects myself [2], until #15990 [3] is 
done. I think this sort of binary split junction will come handy quite 
often and it would be great to have it in the standard library.

Cheers,
Rafał

[1] 
https://github.com/rkrzewski/akka-cluster-etcd/blob/master/etcd-client/src/main/scala/pl/caltha/akka/streams/EitherJunction.scala
[2] 
https://github.com/rkrzewski/akka-cluster-etcd/blob/master/etcd-client/src/main/scala/pl/caltha/akka/http/HttpRedirects.scala
[3] https://github.com/akka/akka/issues/15990

W dniu poniedziałek, 11 maja 2015 00:22:25 UTC+2 użytkownik 
[email protected] napisał:
>
> There seems to be no way to express this (simple) shape using a 
> `FlexiRoute`. A naive version:
>
>   class SplitShape[A](init: FanOutShape.Init[A] = 
> FanOutShape.Name[A]("Split"))
>     extends FanOutShape[A](init) {
>
>     val whenTrue = newOutlet[A]("whenTrue")
>     val whenFalse = newOutlet[A]("whenFalse")
>
>     protected def construct(init: FanOutShape.Init[A]) = new 
> SplitShape(init)
>   }
>
>   class Split[A](predicate: A => Boolean)
>     extends FlexiRoute[A, SplitShape[A]](new SplitShape[A], 
> OperationAttributes.name("PartialOutput")) {
>
>     import FlexiRoute._
>
>     def createRouteLogic(p: PortT) = new RouteLogic[A] {
>       def initialState = State(DemandFromAny(p)) { (ctx, port, element) =>
>         import p._
>
>         val result = predicate(element)
>
>         (result, port) match {
>           case (true,  `whenTrue`) => ctx.emit(whenTrue)(element)
>           case (false, `whenFalse`) => ctx.emit(whenFalse)(element)
>           case (true,  `whenFalse`) =>
>             println("lost element " + element)
>           case (false, `whenTrue`) =>
>             println("lost element " + element)
>           case _ => sys error "Unknown port"
>         }
>
>         SameState
>       }
>     }
>   }
>
> It seems (and I might be mistaken) that the demand and availability of 
> elements are tied together. If I would replace the 'lost element' cases 
> with placing the elements in a buffer, they would only grow as the 
> 'onInput' method is only called when input is available, not when there is 
> demand, regardless of input.
>

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
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