Class TransformingSendPort<T>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.DelegatingSendPort<T>
-
- co.paralleluniverse.strands.channels.TransformingSendPort<T>
-
- All Implemented Interfaces:
co.paralleluniverse.common.util.DelegatingEquals
,Port<T>
,PortAutoCloseable
,SendPort<T>
,java.lang.AutoCloseable
public class TransformingSendPort<T> extends DelegatingSendPort<T>
-
-
Field Summary
-
Fields inherited from class co.paralleluniverse.strands.channels.DelegatingSendPort
target
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <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 thein
channel and writes values to this channel.<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 thein
channel and writes values to this channel.TransformingSendPort<T>
filter(com.google.common.base.Predicate<T> pred)
Returns aTransformingSendPort
that filters messages that satisfy a predicate before sending to this channel.<S> TransformingSendPort<S>
flatMap(Channel<S> pipe, com.google.common.base.Function<S,ReceivePort<T>> f)
Returns aSendPort
that sends messages that are transformed by a given flat-mapping function into this channel.<S> TransformingSendPort<S>
map(com.google.common.base.Function<S,T> f)
Returns aTransformingSendPort
that transforms messages by applying a given mapping function before sending this channel.<S> TransformingSendPort<S>
reduce(co.paralleluniverse.common.util.Function2<T,S,T> f, T init)
Returns aTransformingSendPort
to which sending messages that are transformed towards a channel by a reduction function.-
Methods inherited from class co.paralleluniverse.strands.channels.DelegatingSendPort
close, close, equals, hashCode, send, send, send, toString, trySend
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface co.paralleluniverse.strands.channels.PortAutoCloseable
isClosed
-
-
-
-
Method Detail
-
filter
public TransformingSendPort<T> filter(com.google.common.base.Predicate<T> pred)
Returns aTransformingSendPort
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 samehashCode
aschannel
and isequal
to it.- Parameters:
pred
- the filtering predicate- Returns:
- A
TransformingSendPort
that will send only those messages which satisfy the predicate (i.e. the predicate returnstrue
) to the given channel.
-
map
public <S> TransformingSendPort<S> map(com.google.common.base.Function<S,T> f)
Returns aTransformingSendPort
that transforms messages by applying a given mapping function before sending this channel.The returned
TransformingSendPort
has the samehashCode
aschannel
and isequal
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 aTransformingSendPort
to which sending messages that are transformed towards a channel by a reduction function.The returned
TransformingSendPort
has the samehashCode
aschannel
and isequal
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 aSendPort
that sends messages that are transformed by a given flat-mapping function into this channel. Unlikemap
, the mapping function does not returns a single output message for every input message, but a newReceivePort
. 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 ofChannels.toReceivePort(Iterable)
. To emit no values, the function can returnChannels.emptyReceivePort()
ornull
.If multiple producers send messages into the channel, the messages from the
ReceivePort
s returned by the mapping function may be interleaved with other messages.The returned
SendPort
has the samehashCode
aschannel
and isequal
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 thein
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 channeltransformer
- the transforming operation- Returns:
- A
TransformingSendPort
wrapping thein
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 thein
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 fiberin
- the input channeltransformer
- the transforming operation- Returns:
- A
TransformingSendPort
wrapping thein
channel.
-
-