idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
25,000
public final static < T > Optional < Seq < T > > streamToOptional ( final Stream < T > stream ) { final List < T > collected = stream . collect ( java . util . stream . Collectors . toList ( ) ) ; if ( collected . size ( ) == 0 ) return Optional . empty ( ) ; return Optional . of ( Seq . fromIterable ( collected ) ) ; }
Create an Optional containing a List materialized from a Stream
25,001
public final static < T > Stream < T > optionalToStream ( final Optional < T > optional ) { if ( optional . isPresent ( ) ) return Stream . of ( optional . get ( ) ) ; return Stream . of ( ) ; }
Convert an Optional to a Stream
25,002
public final static < T > CompletableFuture < List < T > > streamToCompletableFuture ( final Stream < T > stream ) { return CompletableFuture . completedFuture ( stream . collect ( Collectors . toList ( ) ) ) ; }
Create a CompletableFuture containing a List materialized from a Stream
25,003
public final static < T > Stream < T > completableFutureToStream ( final CompletableFuture < T > future ) { return Stream . of ( future . join ( ) ) ; }
Convert a CompletableFuture to a Stream
25,004
@ SuppressWarnings ( "unchecked" ) public final static < T > Tuple4 < Stream < T > , Stream < T > , Stream < T > , Stream < T > > quadruplicate ( final Stream < T > stream ) { final Stream < Stream < T > > its = Streams . toBufferingCopier ( stream . iterator ( ) , 4 ) . stream ( ) . map ( it -> Streams . stream ( it ) ) ; final Iterator < Stream < T > > it = its . iterator ( ) ; return new Tuple4 ( it . next ( ) , it . next ( ) , it . next ( ) , it . next ( ) ) ; }
Makes four copies of a Stream Buffers intermediate values leaders may change positions so a limit can be safely applied to the leading stream . Not thread - safe .
25,005
public static final < T > Stream < T > appendStream ( final Stream < T > stream1 , final Stream < T > append ) { return Stream . concat ( stream1 , append ) ; }
Append Stream to this Stream
25,006
public static final < T > Stream < T > prependStream ( final Stream < T > stream1 , final Stream < T > prepend ) { return Stream . concat ( prepend , stream1 ) ; }
Prepend Stream to this Stream
25,007
public static < U > Stream < U > dropWhile ( final Stream < U > stream , final Predicate < ? super U > predicate ) { return StreamSupport . stream ( new SkipWhileSpliterator < U > ( stream . spliterator ( ) , predicate ) , stream . isParallel ( ) ) ; }
skip elements in a Stream while Predicate holds true
25,008
public static < U > Stream < U > cycle ( final Stream < U > s ) { return cycle ( Streamable . fromStream ( s ) ) ; }
Create a new Stream that infiniteable cycles the provided Stream
25,009
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) public static < R > Seq < R > reduce ( final Stream < R > stream , final Iterable < ? extends Monoid < R > > reducers ) { return Seq . fromIterable ( new MultiReduceOperator < R > ( stream ) . reduce ( reducers ) ) ; }
Simultaneously reduce a stream with multiple reducers
25,010
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) public static < R > Seq < R > reduce ( final Stream < R > stream , final Stream < ? extends Monoid < R > > reducers ) { return reduce ( stream , Seq . fromIterable ( ( List ) reducers . collect ( java . util . stream . Collectors . toList ( ) ) ) ) ; }
Simultanously reduce a stream with multiple reducers
25,011
public final static < T > Stream < T > cycleUntil ( final Stream < T > stream , final Predicate < ? super T > predicate ) { return Streams . takeUntil ( Streams . cycle ( stream ) , predicate ) ; }
Repeat in a Stream until specified predicate holds
25,012
public final static < T , S , R > Stream < R > zipSequence ( final Stream < T > stream , final Stream < ? extends S > second , final BiFunction < ? super T , ? super S , ? extends R > zipper ) { final Iterator < T > left = stream . iterator ( ) ; final Iterator < ? extends S > right = second . iterator ( ) ; return Streams . stream ( new Iterator < R > ( ) { public boolean hasNext ( ) { return left . hasNext ( ) && right . hasNext ( ) ; } public R next ( ) { return zipper . apply ( left . next ( ) , right . next ( ) ) ; } } ) ; }
Generic zip function . E . g . Zipping a Stream and a Sequence
25,013
public final static < T > Stream < Vector < T > > grouped ( final Stream < T > stream , final int groupSize ) { return StreamSupport . stream ( new GroupingSpliterator < > ( stream . spliterator ( ) , ( ) -> Vector . empty ( ) , c -> Vector . fromIterable ( c ) , groupSize ) , stream . isParallel ( ) ) ; }
Group elements in a Stream by size
25,014
public final static < T > Stream < T > scanLeft ( final Stream < T > stream , final Monoid < T > monoid ) { final Iterator < T > it = stream . iterator ( ) ; return Streams . stream ( new Iterator < T > ( ) { boolean init = false ; T next = monoid . zero ( ) ; public boolean hasNext ( ) { if ( ! init ) return true ; return it . hasNext ( ) ; } public T next ( ) { if ( ! init ) { init = true ; return monoid . zero ( ) ; } return next = monoid . apply ( next , it . next ( ) ) ; } } ) ; }
Scan left using supplied Monoid
25,015
public static < T > boolean xMatch ( final Stream < T > stream , final int num , final Predicate < ? super T > c ) { return stream . filter ( t -> c . test ( t ) ) . collect ( java . util . stream . Collectors . counting ( ) ) == num ; }
Check that there are specified number of matches of predicate in the Stream
25,016
public final static < T , R > R foldMap ( final Stream < T > stream , final Function < ? super T , ? extends R > mapper , final Monoid < R > reducer ) { return reducer . foldLeft ( stream . map ( mapper ) ) ; }
Attempt to transform this Stream to the same type as the supplied Monoid using supplied function Then use Monoid to reduce values
25,017
public static < T > Stream < T > intersperse ( final Stream < T > stream , final T value ) { return stream . flatMap ( t -> Stream . of ( value , t ) ) . skip ( 1 ) ; }
Returns a stream with a given value interspersed between any two values of this stream .
25,018
@ SuppressWarnings ( "unchecked" ) public static < T , U > Stream < U > ofType ( final Stream < T > stream , final Class < ? extends U > type ) { return stream . filter ( type :: isInstance ) . map ( t -> ( U ) t ) ; }
Keep only those elements in a stream that are of a given type .
25,019
public final static < T > Stream < Character > flatMapCharSequence ( final Stream < T > stream , final Function < ? super T , CharSequence > fn ) { return stream . flatMap ( fn . andThen ( CharSequence :: chars ) . andThen ( s -> s . mapToObj ( i -> Character . toChars ( i ) [ 0 ] ) ) ) ; }
rename - flatMapCharSequence
25,020
public final static < T > Stream < String > flatMapFile ( final Stream < T > stream , final Function < ? super T , File > fn ) { return stream . flatMap ( fn . andThen ( f -> ExceptionSoftener . softenSupplier ( ( ) -> Files . lines ( Paths . get ( f . getAbsolutePath ( ) ) ) ) . get ( ) ) ) ; }
Perform a flatMap operation where the result will be a flattened stream of Strings from the text loaded from the supplied files .
25,021
public final static < T > Stream < String > flatMapURL ( final Stream < T > stream , final Function < ? super T , URL > fn ) { return stream . flatMap ( fn . andThen ( url -> ExceptionSoftener . softenSupplier ( ( ) -> { final BufferedReader in = new BufferedReader ( new InputStreamReader ( url . openStream ( ) ) ) ; return in . lines ( ) ; } ) . get ( ) ) ) ; }
Perform a flatMap operation where the result will be a flattened stream of Strings from the text loaded from the supplied URLs
25,022
public final static < T > Stream < String > flatMapBufferedReader ( final Stream < T > stream , final Function < ? super T , BufferedReader > fn ) { return stream . flatMap ( fn . andThen ( in -> ExceptionSoftener . softenSupplier ( ( ) -> { return in . lines ( ) ; } ) . get ( ) ) ) ; }
Perform a flatMap operation where the result will be a flattened stream of Strings from the text loaded from the supplied BufferedReaders
25,023
public final static < T > Stream < Seq < T > > groupedStatefullyUntil ( final Stream < T > stream , final BiPredicate < Seq < ? super T > , ? super T > predicate ) { return StreamSupport . stream ( new GroupedStatefullySpliterator < > ( stream . spliterator ( ) , ( ) -> Seq . of ( ) , Function . identity ( ) , predicate . negate ( ) ) , stream . isParallel ( ) ) ; }
Group data in a Stream using knowledge of the current batch and the next entry to determing grouping limits
25,024
public final static < T > Stream < Seq < T > > groupedUntil ( final Stream < T > stream , final Predicate < ? super T > predicate ) { return groupedWhile ( stream , predicate . negate ( ) ) ; }
Group a Stream until the supplied predicate holds
25,025
public final static < T > Stream < T > debounce ( final Stream < T > stream , final long time , final TimeUnit t ) { return new DebounceOperator < > ( stream ) . debounce ( time , t ) ; }
Allow one element through per time period drop all other elements in that time period
25,026
public final static < T > Stream < T > onePer ( final Stream < T > stream , final long time , final TimeUnit t ) { return new OnePerOperator < > ( stream ) . onePer ( time , t ) ; }
emit one element per time period
25,027
public static MutableLong fromExternal ( final LongSupplier s , final LongConsumer c ) { return new MutableLong ( ) { public long getAsLong ( ) { return s . getAsLong ( ) ; } public Long get ( ) { return getAsLong ( ) ; } public MutableLong set ( final long value ) { c . accept ( value ) ; return this ; } } ; }
Construct a MutableLong that gets and sets an external value using the provided Supplier and Consumer
25,028
public < R > R submit ( final Function < RS , R > fn ) { return submit ( ( ) -> fn . apply ( this . results ) ) ; }
This method allows the SimpleReact Executor to be reused by JDK parallel streams . It is best used when collectResults and block are called explicitly for finer grained control over the blocking conditions .
25,029
public < T > T submit ( final Callable < T > callable ) { if ( taskExecutor instanceof ForkJoinPool ) { try { return ( ( ForkJoinPool ) taskExecutor ) . submit ( callable ) . get ( ) ; } catch ( final ExecutionException e ) { throw ExceptionSoftener . throwSoftenedException ( e ) ; } catch ( final InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw ExceptionSoftener . throwSoftenedException ( e ) ; } } try { return callable . call ( ) ; } catch ( final Exception e ) { throw new RuntimeException ( e ) ; } }
This method allows the SimpleReact Executor to be reused by JDK parallel streams
25,030
public static < R > Function0 < R > memoizeSupplierAsync ( final Supplier < R > fn , ScheduledExecutorService ex , long updateRateInMillis ) { return ( ) -> Memoize . memoizeFunctionAsync ( a -> fn . get ( ) , ex , updateRateInMillis ) . apply ( "k" ) ; }
Memoize a Supplier and update the cached values asynchronously using the provided Scheduled Executor Service Does not support null keys
25,031
public static < T1 , T2 , R > Function2 < T1 , T2 , R > memoizeBiFunction ( final BiFunction < T1 , T2 , R > fn ) { Function1 < Tuple2 < T1 , T2 > , R > memoise2 = memoizeFunction ( ( final Tuple2 < T1 , T2 > pair ) -> fn . apply ( pair . _1 ( ) , pair . _2 ( ) ) ) ; return ( t1 , t2 ) -> memoise2 . apply ( tuple ( t1 , t2 ) ) ; }
Convert a BiFunction into one that caches it s result
25,032
public static < T1 , T2 , T3 , R > Function3 < T1 , T2 , T3 , R > memoizeTriFunction ( final Function3 < T1 , T2 , T3 , R > fn , final Cacheable < R > cache ) { Function1 < Tuple3 < T1 , T2 , T3 > , R > memoise2 = memoizeFunction ( ( final Tuple3 < T1 , T2 , T3 > triple ) -> fn . apply ( triple . _1 ( ) , triple . _2 ( ) , triple . _3 ( ) ) , cache ) ; return ( t1 , t2 , t3 ) -> memoise2 . apply ( tuple ( t1 , t2 , t3 ) ) ; }
Convert a TriFunction into one that caches it s result
25,033
public static < T1 , T2 , T3 , T4 , R > Function4 < T1 , T2 , T3 , T4 , R > memoizeQuadFunction ( final Function4 < T1 , T2 , T3 , T4 , R > fn ) { Function1 < Tuple4 < T1 , T2 , T3 , T4 > , R > memoise2 = memoizeFunction ( ( final Tuple4 < T1 , T2 , T3 , T4 > quad ) -> fn . apply ( quad . _1 ( ) , quad . _2 ( ) , quad . _3 ( ) , quad . _4 ( ) ) ) ; return ( t1 , t2 , t3 , t4 ) -> memoise2 . apply ( tuple ( t1 , t2 , t3 , t4 ) ) ; }
Convert a QuadFunction into one that caches it s result
25,034
public static < T > Predicate < T > memoizePredicate ( final Predicate < T > p , final Cacheable < Boolean > cache ) { final Function < T , Boolean > memoised = memoizeFunction ( ( Function < T , Boolean > ) t -> p . test ( t ) , cache ) ; LazyImmutable < Boolean > nullR = LazyImmutable . def ( ) ; return ( t ) -> t == null ? nullR . computeIfAbsent ( ( ) -> p . test ( null ) ) : memoised . apply ( t ) ; }
Convert a Predicate into one that caches it s result
25,035
public static < T > Mono < T > anyOf ( Mono < T > ... fts ) { return Mono . from ( Future . anyOf ( futures ( fts ) ) ) ; }
Select the first Mono to complete
25,036
public static < T1 , T2 , R1 , R2 , R > Mono < R > forEach3 ( Mono < ? extends T1 > value1 , Function < ? super T1 , ? extends Mono < R1 > > value2 , BiFunction < ? super T1 , ? super R1 , ? extends Mono < R2 > > value3 , Function3 < ? super T1 , ? super R1 , ? super R2 , ? extends R > yieldingFunction ) { Future < ? extends R > res = Future . fromPublisher ( value1 ) . flatMap ( in -> { Future < R1 > a = Future . fromPublisher ( value2 . apply ( in ) ) ; return a . flatMap ( ina -> { Future < R2 > b = Future . fromPublisher ( value3 . apply ( in , ina ) ) ; return b . map ( in2 -> yieldingFunction . apply ( in , ina , in2 ) ) ; } ) ; } ) ; return Mono . from ( res ) ; }
Perform a For Comprehension over a Mono accepting 2 generating functions . This results in a three level nested internal iteration over the provided Monos .
25,037
public static < T , R1 , R > Mono < R > forEach ( Mono < ? extends T > value1 , Function < ? super T , Mono < R1 > > value2 , BiFunction < ? super T , ? super R1 , ? extends R > yieldingFunction ) { Future < R > res = Future . fromPublisher ( value1 ) . flatMap ( in -> { Future < R1 > a = Future . fromPublisher ( value2 . apply ( in ) ) ; return a . map ( ina -> yieldingFunction . apply ( in , ina ) ) ; } ) ; return Mono . from ( res ) ; }
Perform a For Comprehension over a Mono accepting a generating function . This results in a two level nested internal iteration over the provided Monos .
25,038
public static < T > Mono < T > fromIterable ( Iterable < T > t ) { return Mono . from ( Flux . fromIterable ( t ) ) ; }
Construct a Mono from Iterable by taking the first value from Iterable
25,039
public static MutableShort fromExternal ( final Supplier < Short > s , final Consumer < Short > c ) { return new MutableShort ( ) { public short getAsShort ( ) { return s . get ( ) ; } public Short get ( ) { return getAsShort ( ) ; } public MutableShort set ( final short value ) { c . accept ( value ) ; return this ; } } ; }
Construct a MutableShort that gets and sets an external value using the provided Supplier and Consumer
25,040
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
25,041
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 .
25,042
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
25,043
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
25,044
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
25,045
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
25,046
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
25,047
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
25,048
public static < T > Mutable < T > fromExternal ( final Supplier < T > s , final Consumer < T > c ) { return new Mutable < T > ( ) { public T get ( ) { return s . get ( ) ; } 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
25,049
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
25,050
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
25,051
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
25,052
public static < T > Optional < T > narrowK ( final Higher < optional , T > Optional ) { return ( ( OptionalKind < T > ) Optional ) . boxed ; }
Convert the HigherKindedType definition for a Optional into
25,053
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 .
25,054
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 .
25,055
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
25,056
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 .
25,057
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
25,058
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
25,059
@ 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
25,060
@ 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
25,061
@ 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
25,062
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
25,063
@ 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
25,064
public void subscribeTo ( final K key , final Subscriber < V > subscriber ) { registered . get ( key ) . stream ( ) . subscribe ( subscriber ) ; }
Subscribe synchronously to a pipe
25,065
public void subscribeTo ( final K key , final Subscriber < V > subscriber , final Executor subscribeOn ) { CompletableFuture . runAsync ( ( ) -> subscribeTo ( key , subscriber ) , subscribeOn ) ; }
Subscribe asynchronously to a pipe
25,066
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
25,067
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
25,068
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
25,069
public < U > FutureStream < U > from ( final CompletableFuture < U > cf ) { return this . constructFutures ( Stream . of ( cf ) ) ; }
Construct a FutureStream containing a single Future
25,070
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
25,071
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
25,072
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
25,073
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 ; 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 .
25,074
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
25,075
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
25,076
public T set ( final T newValue ) { if ( continuous != null ) continuous . offer ( newValue ) ; setDiscreteIfDiff ( newValue ) ; return newValue ; }
Set the current value of this signal
25,077
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
25,078
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
25,079
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
25,080
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
25,081
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
25,082
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
25,083
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
25,084
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
25,085
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 .
25,086
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
25,087
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
25,088
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
25,089
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 .
25,090
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
25,091
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
25,092
public static MutableInt fromExternal ( final IntSupplier s , final IntConsumer c ) { return new MutableInt ( ) { public int getAsInt ( ) { return s . getAsInt ( ) ; } public Integer get ( ) { return getAsInt ( ) ; } 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
25,093
public static MutableByte fromExternal ( final Supplier < Byte > s , final Consumer < Byte > c ) { return new MutableByte ( ) { public byte getAsByte ( ) { return s . get ( ) ; } public Byte get ( ) { return getAsByte ( ) ; } 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
25,094
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
25,095
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 .
25,096
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!
25,097
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 .
25,098
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
25,099
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