idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
25,000
public static < U > Stream < U > cycle ( final int times , final Streamable < U > s ) { return Stream . iterate ( s . stream ( ) , s1 -> s . stream ( ) ) . limit ( times ) . flatMap ( Function . identity ( ) ) ; }
Create a Stream that finitely cycles the provided Streamable provided number of times
62
15
25,001
public static final < A > Collection < A > toConcurrentLazyCollection ( final Stream < A > stream ) { return toConcurrentLazyCollection ( stream . iterator ( ) ) ; }
Lazily constructs a Collection from specified Stream . Collections iterator may be safely used concurrently by multiple threads .
41
21
25,002
@ Override public < B > OptionalT < W , B > map ( final Function < ? super T , ? extends B > f ) { return new OptionalT < W , B > ( run . map ( o -> o . map ( f ) ) ) ; }
Map the wrapped Optional
56
4
25,003
public static < W extends WitnessType < W > , A > OptionalT < W , A > of ( final AnyM < W , Optional < A > > monads ) { return new OptionalT <> ( monads ) ; }
Construct an OptionalWT from an AnyM that wraps a monad containing OptionalWs
49
16
25,004
public static < T > QueueBasedSubscriber < T > subscriber ( final Counter counter , final int maxConcurrency ) { return new QueueBasedSubscriber <> ( counter , maxConcurrency ) ; }
Create a QueueBasedSubscriber backed by a JDK LinkedBlockingQueue
46
18
25,005
public static < T > QueueBasedSubscriber < T > subscriber ( final Queue < T > q , final Counter counter , final int maxConcurrency ) { return new QueueBasedSubscriber <> ( q , counter , maxConcurrency ) ; }
Create a QueueBasedSubscriber backed by the provided Queue
56
14
25,006
public static < T > QueueBasedSubscriber < T > subscriber ( final QueueFactory < T > factory , final Counter counter , final int maxConcurrency ) { return new QueueBasedSubscriber <> ( factory , counter , maxConcurrency ) ; }
Create a QueueBasedSubscriber backed by a Queue that will be created with the provided QueueFactory
57
23
25,007
public < S , R > Active < W , R > custom ( Function < ? super Higher < W , T > , ? extends S > narrow , Function < ? super S , ? extends Higher < W , R > > fn ) { return Active . of ( fn . apply ( narrow . apply ( single ) ) , def1 ) ; }
Perform a custom operation
71
5
25,008
public static < T > Mutable < T > fromExternal ( final Supplier < T > s , final Consumer < T > c ) { return new Mutable < T > ( ) { @ Override public T get ( ) { return s . get ( ) ; } @ Override public Mutable < T > set ( final T value ) { c . accept ( value ) ; return this ; } } ; }
Construct a Mutable that gets and sets an external value using the provided Supplier and Consumer
86
18
25,009
public static < T1 , T2 , T3 , T4 , T5 , R > Supplier < R > partial5 ( final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4 , final T5 t5 , final Function5 < T1 , T2 , T3 , T4 , T5 , R > quintFunc ) { return ( ) -> quintFunc . apply ( t1 , t2 , t3 , t4 , t5 ) ; }
Returns a Function with 4 arguments applied to the supplied QuintFunction
111
12
25,010
public static < T1 , T2 , T3 , T4 , T5 , T6 , R > Supplier < R > partial6 ( final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4 , final T5 t5 , final T6 t6 , final Function6 < T1 , T2 , T3 , T4 , T5 , T6 , R > hexFunc ) { return ( ) -> hexFunc . apply ( t1 , t2 , t3 , t4 , t5 , t6 ) ; }
Returns a Function with 5 arguments applied to the supplied HexFunction
126
12
25,011
public static < T > OptionalKind < T > narrow ( final Higher < optional , T > future ) { return ( OptionalKind < T > ) future ; }
Convert the raw Higher Kinded Type for OptionalKind types into the OptionalKind type definition class
33
19
25,012
public static < T > Optional < T > narrowK ( final Higher < optional , T > Optional ) { //has to be an OptionalKind as only OptionalKind can implement Higher<optional, T> return ( ( OptionalKind < T > ) Optional ) . boxed ; }
Convert the HigherKindedType definition for a Optional into
56
12
25,013
public static < T1 , T2 , R1 , R2 , R > CompletableFuture < R > forEach3 ( CompletableFuture < ? extends T1 > value1 , Function < ? super T1 , ? extends CompletableFuture < R1 > > value2 , BiFunction < ? super T1 , ? super R1 , ? extends CompletableFuture < R2 > > value3 , Function3 < ? super T1 , ? super R1 , ? super R2 , ? extends R > yieldingFunction ) { return value1 . thenCompose ( in -> { CompletableFuture < R1 > a = value2 . apply ( in ) ; return a . thenCompose ( ina -> { CompletableFuture < R2 > b = value3 . apply ( in , ina ) ; return b . thenApply ( in2 -> yieldingFunction . apply ( in , ina , in2 ) ) ; } ) ; } ) ; }
Perform a For Comprehension over a CompletableFuture accepting 2 generating function . This results in a three level nested internal iteration over the provided CompletableFutures .
207
37
25,014
public static < T , R1 , R > CompletableFuture < R > forEach2 ( CompletableFuture < ? extends T > value1 , Function < ? super T , CompletableFuture < R1 > > value2 , BiFunction < ? super T , ? super R1 , ? extends R > yieldingFunction ) { return value1 . thenCompose ( in -> { CompletableFuture < R1 > a = value2 . apply ( in ) ; return a . thenApply ( ina -> yieldingFunction . apply ( in , ina ) ) ; } ) ; }
Perform a For Comprehension over a CompletableFuture accepting a generating function . This results in a two level nested internal iteration over the provided CompletableFutures .
125
37
25,015
public static < T > CompletableFuture < ReactiveSeq < T > > sequence ( final Stream < ? extends CompletableFuture < T > > fts ) { return sequence ( ReactiveSeq . fromStream ( ( fts ) ) ) ; }
Asynchronous sequence operation that convert a Stream of Futures to a Future with a Stream
56
17
25,016
static < T > void subscribe ( Subscriber < ? super T > s , Iterator < ? extends T > it ) { if ( it == null ) { error ( s , new NullPointerException ( "The iterator is null" ) ) ; return ; } boolean b ; try { b = it . hasNext ( ) ; } catch ( Throwable e ) { error ( s , e ) ; return ; } if ( ! b ) { complete ( s ) ; return ; } s . onSubscribe ( new IterableSubscription < T > ( s , it ) ) ; }
Common method to take an Iterator as a source of values .
123
13
25,017
public static < K , V > Pipes < K , V > of ( final Map < K , Adapter < V > > registered ) { Objects . requireNonNull ( registered ) ; final Pipes < K , V > pipes = new Pipes <> ( ) ; pipes . registered . putAll ( registered ) ; return pipes ; }
Construct a Pipes instance to manage a predefined Map of Adapaters
70
15
25,018
public void push ( final K key , final V value ) { Optional . ofNullable ( registered . get ( key ) ) . ifPresent ( a -> a . offer ( value ) ) ; }
Push a single value synchronously into the Adapter identified by the supplied Key if it exists
41
17
25,019
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public Option < Adapter < V > > get ( final K key ) { return Option . ofNullable ( ( Adapter ) registered . get ( key ) ) ; }
Get the Adapter identified by the specified key
53
8
25,020
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public Option < FutureStream < V > > futureStream ( final K key , final LazyReact builder ) { return get ( key ) . map ( a -> builder . fromStream ( a . stream ( ) ) ) ; }
Create a FutureStream using the provided LazyReact futureStream builder from the Adapter identified by the provided Key
67
22
25,021
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public Option < ReactiveSeq < V > > reactiveSeq ( final K key ) { return get ( key ) . map ( a -> a . stream ( ) ) ; }
Create a ReactiveSeq from the Adapter identified by the provided Key
57
14
25,022
public ListX < V > xValues ( final K key , final long x ) { return get ( key ) . map ( a -> a . stream ( ) . limit ( x ) . to ( ReactiveConvertableSequence :: converter ) . listX ( ) ) . orElse ( ListX . empty ( ) ) ; }
Extract the next x values from the Adapter identified by the provided Key If the Adapter doesn t exist an zero List is returned
70
25
25,023
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public Option < V > oneValue ( final K key ) { final ValueSubscriber < V > sub = ValueSubscriber . subscriber ( ) ; return get ( key ) . peek ( a -> a . stream ( ) . subscribe ( sub ) ) . flatMap ( a -> sub . toMaybe ( ) ) ; }
Extract one value from the selected pipe if it exists
87
11
25,024
public void subscribeTo ( final K key , final Subscriber < V > subscriber ) { registered . get ( key ) . stream ( ) . subscribe ( subscriber ) ; }
Subscribe synchronously to a pipe
36
6
25,025
public void subscribeTo ( final K key , final Subscriber < V > subscriber , final Executor subscribeOn ) { CompletableFuture . runAsync ( ( ) -> subscribeTo ( key , subscriber ) , subscribeOn ) ; }
Subscribe asynchronously to a pipe
49
7
25,026
public void publishTo ( final K key , final Publisher < V > publisher ) { registered . get ( key ) . fromStream ( Spouts . from ( publisher ) ) ; }
Synchronously publish data to the Adapter specified by the provided Key blocking the current thread
37
17
25,027
public void publishToAsync ( final K key , final Publisher < V > publisher ) { SequentialElasticPools . simpleReact . react ( er -> er . of ( publisher ) . peek ( p -> publishTo ( key , p ) ) ) ; }
Asynchronously publish data to the Adapter specified by the provided Key
55
13
25,028
public void close ( final String key ) { Optional . ofNullable ( registered . get ( key ) ) . ifPresent ( a -> a . close ( ) ) ; }
Close the Adapter identified by the provided Key if it exists
36
11
25,029
public < U > FutureStream < U > from ( final CompletableFuture < U > cf ) { return this . constructFutures ( Stream . of ( cf ) ) ; }
Construct a FutureStream containing a single Future
39
8
25,030
public < U > FutureStream < U > constructFutures ( final Stream < CompletableFuture < U > > s ) { final LazyReact toUse = withStreamOfFutures ( true ) ; return toUse . construct ( ( Stream < U > ) s ) ; }
Construct a FutureStream from a Stream of CompletableFutures
62
14
25,031
public < T > FutureStream < T > fromPublisher ( final Publisher < ? extends T > publisher ) { Objects . requireNonNull ( publisher ) ; Publisher < T > narrowed = ( Publisher < T > ) publisher ; return fromStream ( Spouts . from ( narrowed ) ) ; }
Construct a FutureStream from an Publisher
59
7
25,032
public static LazyReact parallelBuilder ( final int parallelism ) { return LazyReact . builder ( ) . executor ( Executors . newFixedThreadPool ( parallelism ) ) . build ( ) ; }
Construct a new LazyReact builder with a new task executor and retry executor with configured number of threads
47
24
25,033
public < U > FutureStream < U > iterate ( final U seed , final UnaryOperator < U > f ) { final Subscription sub = new Subscription ( ) ; final Supplier < U > supplier = new Supplier < U > ( ) { @ SuppressWarnings ( "unchecked" ) U t = ( U ) NONE ; @ Override public U get ( ) { return t = t == NONE ? seed : f . apply ( t ) ; } } ; return construct ( StreamSupport . < U > stream ( new InfiniteClosingSpliteratorFromSupplier < U > ( Long . MAX_VALUE , supplier , sub ) , false ) ) ; }
Iterate infinitely using the supplied seed and function Iteration is synchronized to support multiple threads using the same iterator .
145
22
25,034
public < U > FutureStream < U > generate ( final Supplier < U > generate ) { return construct ( StreamSupport . < U > stream ( new InfiniteClosingSpliteratorFromSupplier < U > ( Long . MAX_VALUE , generate , new Subscription ( ) ) , false ) ) ; }
Generate an infinite Stream
64
5
25,035
public < U > FutureStream < U > generateAsync ( final Supplier < U > s ) { return this . constructFutures ( ReactiveSeq . generate ( ( ) -> 1 ) . map ( n -> CompletableFuture . supplyAsync ( s , getExecutor ( ) ) ) ) ; }
Generate an infinite FutureStream executing the provided Supplier continually and asynhcronously
66
19
25,036
public T set ( final T newValue ) { if ( continuous != null ) continuous . offer ( newValue ) ; setDiscreteIfDiff ( newValue ) ; return newValue ; }
Set the current value of this signal
39
7
25,037
public void addMissingRequests ( ) { int missed = 1 ; long toRequest = 0L ; do { long localQueued = queued . getAndSet ( 0l ) ; Subscription localSub = next . getAndSet ( null ) ; long missedOutput = produced . get ( ) ; Subscription localActive = active . get ( ) ; long reqs = requested . get ( ) + localQueued ; if ( reqs < 0 || toRequest < 0 ) { processAll = true ; if ( localSub != null ) localSub . request ( Long . MAX_VALUE ) ; if ( localActive != null ) localActive . request ( Long . MAX_VALUE ) ; return ; } requested . set ( reqs ) ; if ( localSub != null ) { active . set ( localSub ) ; toRequest += reqs ; } else if ( localQueued != 0 && localActive != null ) { toRequest += reqs ; } missed = wip . accumulateAndGet ( missed , ( a , b ) -> a - b ) ; } while ( missed != 0 ) ; if ( toRequest > 0 ) active . get ( ) . request ( toRequest ) ; }
transfer demand from previous to next
249
6
25,038
public ReactiveTask requestAsync ( final long n ) { return withSubscriptionAndTask ( subscriptionAndTask . map2 ( c -> CompletableFuture . runAsync ( ( ) -> subscriptionAndTask . _1 ( ) . join ( ) . request ( n ) , exec ) ) ) ; }
Asyncrhonously request more elements from the Stream
63
11
25,039
@ Override public < B > EitherT < W , ST , B > map ( final Function < ? super T , ? extends B > f ) { return new EitherT < W , ST , B > ( run . map ( o -> o . map ( f ) ) ) ; }
Map the wrapped Maybe
60
4
25,040
public static < W extends WitnessType < W > , U , ST , R > Function < EitherT < W , ST , U > , EitherT < W , ST , R > > lift ( final Function < ? super U , ? extends R > fn ) { return optTu -> optTu . map ( input -> fn . apply ( input ) ) ; }
Lift a function into one that accepts and returns an MaybeWT This allows multiple monad types to add functionality to existing function and methods
75
27
25,041
public static < W extends WitnessType < W > , ST , A > EitherT < W , ST , A > of ( final AnyM < W , Either < ST , A > > monads ) { return new EitherT <> ( monads ) ; }
Construct an MaybeWT from an AnyM that wraps a monad containing MaybeWs
55
16
25,042
public static < W extends WitnessType < W > , A > EvalT < W , A > of ( final AnyM < W , Eval < A > > monads ) { return new EvalT <> ( monads ) ; }
Construct an EvalWT from an AnyM that wraps a monad containing EvalWs
49
16
25,043
public boolean add ( final T data ) { try { final boolean result = queue . add ( ( T ) nullSafe ( data ) ) ; if ( result ) { if ( sizeSignal != null ) this . sizeSignal . set ( queue . size ( ) ) ; } return result ; } catch ( final IllegalStateException e ) { return false ; } }
Add a single data point to the queue
76
8
25,044
@ Override public boolean offer ( final T data ) { if ( ! open ) { throw new ClosedQueueException ( ) ; } try { final boolean result = producerWait . offer ( ( ) -> this . queue . offer ( ( T ) nullSafe ( data ) , this . offerTimeout , this . offerTimeUnit ) ) ; if ( sizeSignal != null ) this . sizeSignal . set ( queue . size ( ) ) ; return result ; } catch ( final InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw ExceptionSoftener . throwSoftenedException ( e ) ; } }
Offer a single datapoint to this Queue
131
11
25,045
@ Override public boolean close ( ) { this . open = false ; for ( int i = 0 ; i < listeningStreams . get ( ) ; i ++ ) { try { this . queue . offer ( ( T ) POISON_PILL ) ; } catch ( Exception e ) { } } return true ; }
Close this Queue Poison Pills are used to communicate closure to connected Streams A Poison Pill is added per connected Stream to the Queue If a BlockingQueue is backing this async . Queue it will block until able to add to the Queue .
67
52
25,046
@ Override public < R > LazyImmutable < R > map ( final Function < ? super T , ? extends R > fn ) { final T val = get ( ) ; if ( val == UNSET ) return ( LazyImmutable < R > ) this ; else return LazyImmutable . of ( fn . apply ( val ) ) ; }
Map the value stored in this Immutable Closed Value from one Value to another If this is an unitiatilised ImmutableClosedValue an uninitialised closed value will be returned instead
75
38
25,047
public < R > LazyImmutable < ? extends R > flatMap ( final Function < ? super T , ? extends LazyImmutable < ? extends R > > fn ) { final T val = get ( ) ; if ( val == UNSET ) return ( LazyImmutable < R > ) this ; else return fn . apply ( val ) ; }
FlatMap the value stored in Immutable Closed Value from one Value to another If this is an unitiatilised ImmutableClosedValue an uninitialised closed value will be returned instead
75
39
25,048
public T computeIfAbsent ( final Supplier < T > lazy ) { final T val = get ( ) ; if ( val == UNSET ) return setOnceFromSupplier ( lazy ) ; return val ; }
Get the current value or set if it has not been set yet
45
13
25,049
public static < REACTOR extends ReactBuilder > ReactPool < REACTOR > elasticPool ( final Supplier < REACTOR > supplier ) { return new ReactPool <> ( supplier ) ; }
If all REACTORs are in use calling react will create a new REACTOR to handle the extra demand .
42
24
25,050
public < B > MonoT < W , B > flatMapT ( final Function < ? super T , MonoT < W , B > > f ) { MonoT < W , B > r = of ( run . map ( future -> Mono . from ( future . flatMap ( a -> { Mono < B > m = f . apply ( a ) . run . stream ( ) . toList ( ) . get ( 0 ) ; return m ; } ) ) ) ) ; return r ; }
Flat Map the wrapped Mono
104
6
25,051
public static < W extends WitnessType < W > , A > MonoT < W , A > of ( final AnyM < W , Mono < A > > monads ) { return new MonoT <> ( monads ) ; }
Construct an MonoT from an AnyM that wraps a monad containing MonoWs
49
16
25,052
public static MutableInt fromExternal ( final IntSupplier s , final IntConsumer c ) { return new MutableInt ( ) { @ Override public int getAsInt ( ) { return s . getAsInt ( ) ; } @ Override public Integer get ( ) { return getAsInt ( ) ; } @ Override public MutableInt set ( final int value ) { c . accept ( value ) ; return this ; } } ; }
Construct a MutableInt that gets and sets an external value using the provided Supplier and Consumer
94
19
25,053
public static MutableByte fromExternal ( final Supplier < Byte > s , final Consumer < Byte > c ) { return new MutableByte ( ) { @ Override public byte getAsByte ( ) { return s . get ( ) ; } @ Override public Byte get ( ) { return getAsByte ( ) ; } @ Override public MutableByte set ( final byte value ) { c . accept ( value ) ; return this ; } } ; }
Construct a MutableByte that gets and sets an external value using the provided Supplier and Consumer
96
19
25,054
public static final < Y > Predicate < Y > any ( final Class < Y > c ) { return a -> a . getClass ( ) . isAssignableFrom ( c ) ; }
MatchType against any object that is an instance of supplied type
41
12
25,055
public < R1 , R4 > State < S , R4 > forEach2 ( Function < ? super T , State < S , R1 > > value2 , BiFunction < ? super T , ? super R1 , ? extends R4 > yieldingFunction ) { return this . flatMap ( in -> { State < S , R1 > a = value2 . apply ( in ) ; return a . map ( in2 -> { return yieldingFunction . apply ( in , in2 ) ; } ) ; } ) ; }
Perform a For Comprehension over a State accepting a generating function . This results in a two level nested internal iteration over the provided States .
111
29
25,056
public T join ( ) { try { long spin = 1 ; while ( ! done ) { LockSupport . parkNanos ( spin ++ ) ; } if ( completedExceptionally ) throw new SimpleReactCompletionException ( exception ( ) ) ; return result ( ) ; } finally { markComplete ( ) ; } }
Join which can be called exactly once!
66
8
25,057
public static < T > FastFuture < T > fromCompletableFuture ( final CompletableFuture < T > cf ) { final FastFuture < T > f = new FastFuture <> ( ) ; cf . thenAccept ( i -> f . set ( i ) ) ; cf . exceptionally ( t -> { f . completedExceptionally ( t ) ; return f . join ( ) ; } ) ; return f ; }
Internal conversion method to convert CompletableFutures to FastFuture .
88
15
25,058
static void closeOthers ( final Queue active , final List < Queue > all ) { all . stream ( ) . filter ( next -> next != active ) . forEach ( Queue :: closeAndClear ) ; }
Close all queues except the active one
46
7
25,059
static void closeOthers ( final SimpleReactStream active , final List < SimpleReactStream > all ) { all . stream ( ) . filter ( next -> next != active ) . filter ( s -> s instanceof BaseSimpleReactStream ) . forEach ( SimpleReactStream :: cancel ) ; }
Close all streams except the active one
64
7
25,060
@ SafeVarargs public static < U > SimpleReactStream < U > firstOf ( final SimpleReactStream < U > ... futureStreams ) { final List < Tuple2 < SimpleReactStream < U > , QueueReader > > racers = Stream . of ( futureStreams ) . map ( s -> Tuple . tuple ( s , new Queue . QueueReader ( s . toQueue ( ) , null ) ) ) . collect ( Collectors . toList ( ) ) ; while ( true ) { for ( final Tuple2 < SimpleReactStream < U > , Queue . QueueReader > q : racers ) { if ( q . _2 ( ) . notEmpty ( ) ) { EagerFutureStreamFunctions . closeOthers ( q . _2 ( ) . getQueue ( ) , racers . stream ( ) . map ( t -> t . _2 ( ) . getQueue ( ) ) . collect ( Collectors . toList ( ) ) ) ; closeOthers ( q . _1 ( ) , racers . stream ( ) . map ( t -> t . _1 ( ) ) . collect ( Collectors . toList ( ) ) ) ; return q . _1 ( ) . fromStream ( q . _2 ( ) . getQueue ( ) . stream ( q . _1 ( ) . getSubscription ( ) ) ) ; } } LockSupport . parkNanos ( 1l ) ; } }
Return first Stream out of provided Streams that starts emitted results
309
12
25,061
public static < T > MultipleStreamSource < T > ofMultiple ( final QueueFactory < ? > q ) { Objects . requireNonNull ( q ) ; return new MultipleStreamSource < T > ( StreamSource . of ( q ) . createQueue ( ) ) ; }
Construct a StreamSource that supports multiple readers of the same data backed by a Queue created from the supplied QueueFactory
57
24
25,062
public < T > PushableFutureStream < T > futureStream ( final LazyReact s ) { final Queue < T > q = createQueue ( ) ; return new PushableFutureStream < T > ( q , s . fromStream ( q . stream ( ) ) ) ; }
Create a pushable FutureStream using the supplied ReactPool
61
11
25,063
public < T > PushableStream < T > stream ( ) { final Queue < T > q = createQueue ( ) ; return new PushableStream < T > ( q , q . jdkStream ( ) ) ; }
Create a pushable JDK 8 Stream
48
8
25,064
public static Runnable softenRunnable ( final CheckedRunnable s ) { return ( ) -> { try { s . run ( ) ; } catch ( final Throwable e ) { throw throwSoftenedException ( e ) ; } } ; }
Soften a Runnable that throws a ChecekdException into a plain old Runnable
54
21
25,065
public static < T > Supplier < T > softenSupplier ( final CheckedSupplier < T > s ) { return ( ) -> { try { return s . get ( ) ; } catch ( final Throwable e ) { throw throwSoftenedException ( e ) ; } } ; }
Soften a Supplier that throws a ChecekdException into a plain old Supplier
61
19
25,066
public static < T > Supplier < T > softenCallable ( final Callable < T > s ) { return ( ) -> { try { return s . call ( ) ; } catch ( final Throwable e ) { throw throwSoftenedException ( e ) ; } } ; }
Soften a Callable that throws a ChecekdException into a Supplier
59
17
25,067
public static BooleanSupplier softenBooleanSupplier ( final CheckedBooleanSupplier s ) { return ( ) -> { try { return s . getAsBoolean ( ) ; } catch ( final Throwable e ) { throw throwSoftenedException ( e ) ; } } ; }
Soften a BooleanSuppler that throws a checked exception into one that still throws the exception but doesn t need to declare it .
60
26
25,068
public static < X extends Throwable > void throwIf ( final X e , final Predicate < X > p ) { if ( p . test ( e ) ) throw ExceptionSoftener . < RuntimeException > uncheck ( e ) ; }
Throw the exception as upwards if the predicate holds otherwise do nothing
50
12
25,069
public static < X extends Throwable > void throwOrHandle ( final X e , final Predicate < X > p , final Consumer < X > handler ) { if ( p . test ( e ) ) throw ExceptionSoftener . < RuntimeException > uncheck ( e ) ; else handler . accept ( e ) ; }
Throw the exception as upwards if the predicate holds otherwise pass to the handler
66
14
25,070
public static < T , R1 , R > Optional < R > forEach2 ( Optional < ? extends T > value1 , Function < ? super T , Optional < R1 > > value2 , BiFunction < ? super T , ? super R1 , ? extends R > yieldingFunction ) { return value1 . flatMap ( in -> { Optional < R1 > a = value2 . apply ( in ) ; return a . map ( in2 -> yieldingFunction . apply ( in , in2 ) ) ; } ) ; }
Perform a For Comprehension over a Optional accepting a generating function . This results in a two level nested internal iteration over the provided Optionals .
111
30
25,071
@ Synchronized ( "lock" ) public void disconnect ( final ReactiveSeq < T > stream ) { Option < Queue < T >> o = streamToQueue . get ( stream ) ; distributor . removeQueue ( streamToQueue . getOrElse ( stream , new Queue <> ( ) ) ) ; this . streamToQueue = streamToQueue . remove ( stream ) ; this . index -- ; }
Topic will maintain a queue for each Subscribing Stream If a Stream is finished with a Topic it is good practice to disconnect from the Topic so messages will no longer be stored for that Stream
88
38
25,072
public static < T > Future < T > narrowK ( final Higher < future , T > future ) { return ( Future < T > ) future ; }
Convert the raw Higher Kinded Type for FutureType types into the FutureType type definition class
32
19
25,073
public static < T > Future < T > anyOf ( Future < T > ... fts ) { CompletableFuture < T > [ ] array = new CompletableFuture [ fts . length ] ; for ( int i = 0 ; i < fts . length ; i ++ ) { array [ i ] = fts [ i ] . getFuture ( ) ; } return ( Future < T > ) Future . of ( CompletableFuture . anyOf ( array ) ) ; }
Select the first Future to complete
103
6
25,074
public static < T > Future < T > fromPublisher ( final Publisher < T > pub , final Executor ex ) { final ValueSubscriber < T > sub = ValueSubscriber . subscriber ( ) ; pub . subscribe ( sub ) ; return sub . toFutureAsync ( ex ) ; }
Construct a Future asynchronously that contains a single value extracted from the supplied reactive - streams Publisher
62
19
25,075
public static < T > Future < T > fromIterable ( final Iterable < T > iterable ) { if ( iterable instanceof Future ) { return ( Future ) iterable ; } return Future . ofResult ( Eval . fromIterable ( iterable ) ) . map ( e -> e . get ( ) ) ; }
Construct a Future syncrhonously that contains a single value extracted from the supplied Iterable
69
18
25,076
public static < T , X extends Throwable > Future < T > fromTry ( final Try < T , X > value ) { return value . fold ( s -> Future . ofResult ( s ) , e -> Future . < T > of ( CompletableFutures . error ( e ) ) ) ; }
Construct a Future syncrhonously from the Supplied Try
66
12
25,077
public static < T > Future < ReactiveSeq < T > > sequence ( final Stream < ? extends Future < T > > fts ) { return sequence ( ReactiveSeq . fromStream ( fts ) ) ; }
Sequence operation that convert a Stream of Futures to a Future with a Stream
48
16
25,078
@ Deprecated //use foldAsync public < R > Future < R > visitAsync ( Function < ? super T , ? extends R > success , Function < ? super Throwable , ? extends R > failure ) { return foldAsync ( success , failure ) ; }
Non - blocking visit on the state of this Future
54
10
25,079
public < R > R fold ( Function < ? super T , ? extends R > success , Function < ? super Throwable , ? extends R > failure ) { try { return success . apply ( future . join ( ) ) ; } catch ( Throwable t ) { return failure . apply ( t ) ; } }
Blocking analogue to visitAsync . Visit the state of this Future block until ready .
65
17
25,080
public < R > Future < R > map ( final Function < ? super T , ? extends R > fn , Executor ex ) { return new Future < R > ( future . thenApplyAsync ( fn , ex ) ) ; }
Asyncrhonous transform operation
48
7
25,081
public < R > Future < R > flatMapCf ( final Function < ? super T , ? extends CompletionStage < ? extends R > > mapper ) { return Future . < R > of ( future . < R > thenCompose ( t -> ( CompletionStage < R > ) mapper . apply ( t ) ) ) ; }
A flatMap operation that accepts a CompleteableFuture CompletionStage as the return type
73
17
25,082
public Future < T > recover ( final Function < ? super Throwable , ? extends T > fn ) { return Future . of ( toCompletableFuture ( ) . exceptionally ( ( Function ) fn ) ) ; }
Returns a new Future that when this Future completes exceptionally is executed with this Future exception as the argument to the supplied function . Otherwise if this Future completes normally applyHKT the returned Future also completes normally with the same value .
45
44
25,083
public < R > Future < R > map ( final Function < ? super T , R > success , final Function < Throwable , R > failure ) { return Future . of ( future . thenApply ( success ) . exceptionally ( failure ) ) ; }
Map this Future differently depending on whether the previous stage completed successfully or failed
52
14
25,084
public static < T > Future < T > ofResult ( final T result ) { return Future . of ( CompletableFuture . completedFuture ( result ) ) ; }
Construct a successfully completed Future from the given value
35
9
25,085
public static < T > Future < T > ofError ( final Throwable error ) { final CompletableFuture < T > cf = new CompletableFuture <> ( ) ; cf . completeExceptionally ( error ) ; return Future . < T > of ( cf ) ; }
Construct a completed - with - error Future from the given Exception
59
12
25,086
public static < T > Future < T > of ( final Supplier < T > s ) { return Future . of ( CompletableFuture . supplyAsync ( s ) ) ; }
Create a Future object that asyncrhonously populates using the Common ForkJoinPool from the user provided Supplier
38
24
25,087
public static < T > Future < T > of ( final Supplier < T > s , final Executor ex ) { return Future . of ( CompletableFuture . supplyAsync ( s , ex ) ) ; }
Create a Future object that asyncrhonously populates using the provided Executor and Supplier
45
20
25,088
public static MutableFloat fromExternal ( final Supplier < Float > s , final Consumer < Float > c ) { return new MutableFloat ( ) { @ Override public float getAsFloat ( ) { return s . get ( ) ; } @ Override public Float get ( ) { return getAsFloat ( ) ; } @ Override public MutableFloat set ( final float value ) { c . accept ( value ) ; return this ; } } ; }
Construct a MutableFloat that gets and sets an external value using the provided Supplier and Consumer
96
19
25,089
public static MutableBoolean fromExternal ( final BooleanSupplier s , final Consumer < Boolean > c ) { return new MutableBoolean ( ) { @ Override public boolean getAsBoolean ( ) { return s . getAsBoolean ( ) ; } @ Override public Boolean get ( ) { return getAsBoolean ( ) ; } @ Override public MutableBoolean set ( final boolean value ) { c . accept ( value ) ; return this ; } } ; }
Construct a MutableBoolean that gets and sets an external value using the provided Supplier and Consumer
102
20
25,090
public < T > SimpleReactStream < T > fromPublisher ( final Publisher < ? extends T > publisher ) { Objects . requireNonNull ( publisher ) ; Publisher < T > narrowed = ( Publisher < T > ) publisher ; return from ( Spouts . from ( narrowed ) ) ; }
Construct a SimpleReactStream from an Publisher
60
9
25,091
public static SimpleReact parallelBuilder ( final int parallelism ) { return SimpleReact . builder ( ) . executor ( new ForkJoinPool ( parallelism ) ) . async ( true ) . build ( ) ; }
Construct a new SimpleReact builder with a new task executor and retry executor with configured number of threads
46
23
25,092
@ SuppressWarnings ( "unchecked" ) public < U > SimpleReactStream < U > fromIterable ( final Iterable < U > iter ) { if ( iter instanceof SimpleReactStream ) { return ( SimpleReactStream < U > ) iter ; } return this . from ( StreamSupport . stream ( Spliterators . spliteratorUnknownSize ( iter . iterator ( ) , Spliterator . ORDERED ) , false ) ) ; }
Start a reactive flow from a JDK Iterator
97
10
25,093
public < T2 , T3 , R1 , R2 , R3 > Unrestricted < R3 > forEach4 ( Function < ? super T , ? extends Unrestricted < R1 > > value2 , BiFunction < ? super T , ? super R1 , ? extends Unrestricted < R2 > > value3 , Function3 < ? super T , ? super R1 , ? super R2 , ? extends Unrestricted < R3 > > value4 ) { return this . flatMap ( in -> { Unrestricted < R1 > a = value2 . apply ( in ) ; return a . flatMap ( ina -> { Unrestricted < R2 > b = value3 . apply ( in , ina ) ; return b . flatMap ( inb -> { Unrestricted < R3 > c = value4 . apply ( in , ina , inb ) ; return c ; } ) ; } ) ; } ) ; }
Perform a For Comprehension over a Unrestricted accepting 3 generating function . This results in a four level nested internal iteration over the provided Computationss .
198
32
25,094
public < T2 , R1 , R2 > Unrestricted < R2 > forEach3 ( Function < ? super T , ? extends Unrestricted < R1 > > value2 , BiFunction < ? super T , ? super R1 , ? extends Unrestricted < R2 > > value3 ) { return this . flatMap ( in -> { Unrestricted < R1 > a = value2 . apply ( in ) ; return a . flatMap ( ina -> { Unrestricted < R2 > b = value3 . apply ( in , ina ) ; return b ; } ) ; } ) ; }
Perform a For Comprehension over a Unrestricted accepting 2 generating function . This results in a three level nested internal iteration over the provided Computationss .
128
32
25,095
public < R1 > Unrestricted < R1 > forEach2 ( Function < ? super T , Unrestricted < R1 > > value2 ) { return this . flatMap ( in -> { Unrestricted < R1 > a = value2 . apply ( in ) ; return a ; } ) ; }
Perform a For Comprehension over a Unrestricted accepting a generating function . This results in a two level nested internal iteration over the provided Computationss .
64
32
25,096
public static final < T , W extends Unit < T > > Function1 < ? super T , ? extends W > arrowUnit ( Unit < ? > w ) { return t -> ( W ) w . unit ( t ) ; }
Use an existing instance of a type that implements Unit to create a KleisliM arrow for that type
48
21
25,097
public static < T > Try < T , Throwable > CofromPublisher ( final Publisher < T > pub ) { return new Try <> ( LazyEither . fromPublisher ( pub ) , new Class [ 0 ] ) ; }
Construct a Try that contains a single value extracted from the supplied reactive - streams Publisher
49
16
25,098
public static < T , X extends Throwable > Try < T , X > fromIterable ( final Iterable < T > iterable , T alt ) { if ( iterable instanceof Try ) { return ( Try ) iterable ; } return new Try <> ( LazyEither . fromIterable ( iterable , alt ) , new Class [ 0 ] ) ; }
Construct a Try that contains a single value extracted from the supplied Iterable
78
14
25,099
@ SafeVarargs public final < R > Try < R , X > mapOrCatch ( CheckedFunction < ? super T , ? extends R , X > fn , Class < ? extends X > ... classes ) { return new Try < R , X > ( xor . flatMap ( i -> safeApply ( i , fn . asFunction ( ) , classes ) ) , this . classes ) ; }
Perform a mapping operation that may catch the supplied Exception types The supplied Exception types are only applied during this map operation
85
23