Class TransformingSendPort<T>

    • Method Detail

      • filter

        public TransformingSendPort<T> filter​(com.google.common.base.Predicate<T> pred)
        Returns a TransformingSendPort that filters messages that satisfy a predicate before sending to this channel. Messages that don't satisfy the predicate will be silently discarded when sent.

        The returned SendPort has the same hashCode as channel and is equal to it.

        Parameters:
        pred - the filtering predicate
        Returns:
        A TransformingSendPort that will send only those messages which satisfy the predicate (i.e. the predicate returns true) to the given channel.
      • map

        public <S> TransformingSendPort<S> map​(com.google.common.base.Function<S,​T> f)
        Returns a TransformingSendPort that transforms messages by applying a given mapping function before sending this channel.

        The returned TransformingSendPort has the same hashCode as channel and is equal to it.

        Parameters:
        f - the mapping function
        Returns:
        a TransformingSendPort that passes messages to the given channel after transforming them by applying the mapping function.
      • reduce

        public <S> TransformingSendPort<S> reduce​(co.paralleluniverse.common.util.Function2<T,​S,​T> f,
                                                  T init)
        Returns a TransformingSendPort to which sending messages that are transformed towards a channel by a reduction function.

        The returned TransformingSendPort has the same hashCode as channel and is equal to it.

        Parameters:
        f - The reduction function.
        init - The initial input to the reduction function.
        Returns:
        a ReceivePort that returns messages that are the result of applying the reduction function to the messages received on the given channel.
      • flatMap

        public <S> TransformingSendPort<S> flatMap​(Channel<S> pipe,
                                                   com.google.common.base.Function<S,​ReceivePort<T>> f)
        Returns a SendPort that sends messages that are transformed by a given flat-mapping function into this channel. Unlike map, the mapping function does not returns a single output message for every input message, but a new ReceivePort. All the returned ports are concatenated and sent to the channel.

        To return a single value the mapping function can make use of Channels.singletonReceivePort(Object). To return a collection, it can make use of Channels.toReceivePort(Iterable). To emit no values, the function can return Channels.emptyReceivePort() or null.

        If multiple producers send messages into the channel, the messages from the ReceivePorts returned by the mapping function may be interleaved with other messages.

        The returned SendPort has the same hashCode as channel and is equal to it.

        Parameters:
        pipe - an intermediate channel used in the flat-mapping operation. Messages are first sent to this channel before being transformed.
        f - the mapping function
        Returns:
        a ReceivePort that returns messages that are the result of applying the mapping function to the messages received on the given channel.
      • fiberTransform

        public <U> TransformingSendPort<U> fiberTransform​(SuspendableAction2<? extends ReceivePort<? super U>,​? extends SendPort<? extends T>> transformer,
                                                          Channel<U> in)
        Spawns a fiber that transforms values read from the in channel and writes values to this channel.

        When the transformation terminates. the output channel is automatically closed. If the transformation terminates abnormally (throws an exception), this channel is closed with that exception.

        Parameters:
        in - the input channel
        transformer - the transforming operation
        Returns:
        A TransformingSendPort wrapping the in channel.
      • fiberTransform

        public <U> TransformingSendPort<U> fiberTransform​(FiberFactory fiberFactory,
                                                          SuspendableAction2<? extends ReceivePort<? super U>,​? extends SendPort<? extends T>> transformer,
                                                          Channel<U> in)
        Spawns a fiber that transforms values read from the in channel and writes values to this channel.

        When the transformation terminates. the output channel is automatically closed. If the transformation terminates abnormally (throws an exception), this channel is closed with that exception.

        Parameters:
        fiberFactory - will be used to create the fiber
        in - the input channel
        transformer - the transforming operation
        Returns:
        A TransformingSendPort wrapping the in channel.