Hi Derek,
Sounds like a great addition. Will you take a stab at it?
/Patrik

On Thu, Apr 7, 2016 at 9:59 PM, Derek Wyatt <[email protected]> wrote:

> Hi guys,
>
> I've been writing some tests for my stream code and have run up against a
> situation where I would like to have expectNextType.  I've implemented
> this myself with a pimp, but I'm wondering if there's a better way?
>
>   implicit class ProbeExtension[T](val p: Probe[T]) {
>     def expectNextType[A](implicit t: ClassTag[A]): p.Self = {
>       p.expectNextPF {
>         case a: A =>
>         case x => fail(s"Expected a $t type but got a
> ${x.getClass.getName}")
>       }
>       p
>     }
>   }
>
> This is mostly useful when the 'A' in question is a derivation of Try[_].
> I tend to write expectNextType[Failure[_]] in these cases.  And, just to
> give some context as to why I would want to do that: My flow components
> might return a Try, which I then pass through a special handling / logging
> flow, which transforms them to a List that is composed with a mapConcat.
> So...
>
> val flowReturningTry: Flow[T, Try[U], NotUsed] = ...
> val handlingAndLogging: Flow[Try[U], U, NotUsed] = Flow[Try[U]].mapConcat
> { /* List(u) or List(), depending on the Try */ }
> val composed: Flow[T, U, NotUsed] =
> flowReturningTry.mapConcat(handlingAndLogging)
>
> Now, when testing flowReturningTry in isolation, the expectNextType is
> useful.
>
> Cheers and thanks,
> Derek
>
> --
> >>>>>>>>>> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Patrik Nordwall
Akka Tech Lead
Lightbend <http://www.lightbend.com/> -  Reactive apps on the JVM
Twitter: @patriknw

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to