public class Fns extends Object
| Constructor and Description |
|---|
Fns() |
| Modifier and Type | Method and Description |
|---|---|
static <A,B extends Iterable<A>> |
cat()
Creates a transducer that transforms a reducing function by accepting
an iterable of the expected input type and reducing it
|
static <R,T> IReducingFunction<R,? super T> |
completing(IStepFunction<R,? super T> sf)
Converts an step function into a complete reducing function.
|
static <A,B,C> ITransducer<A,C> |
compose(ITransducer<B,C> left,
ITransducer<A,B> right)
Composes a transducer with another transducer, yielding a new transducer that
|
static <A> ITransducer<A,A> |
dedupe()
Creates a transducer that transforms a reducing function such that
consecutive identical input values are removed, only a single value
is processed.
|
static <A> ITransducer<A,A> |
drop(long n)
Creates a transducer that transforms a reducing function such that
it skips n inputs, then processes the rest of the inputs.
|
static <A> ITransducer<A,A> |
dropWhile(Predicate<A> p)
Creates a transducer that transforms a reducing function such that
it skips inputs as long as the provided predicate returns true.
|
static <A> ITransducer<A,A> |
filter(Predicate<A> p)
Creates a transducer that transforms a reducing function by applying a
predicate to each input and processing only those inputs for which the
predicate is true.
|
static <R extends Collection<A>,A,B> |
into(ITransducer<A,B> xf,
R init,
Iterable<B> input)
Transduces input into collection using built-in reducing function.
|
static <A> ITransducer<A,A> |
keep(Function<A,A> f)
Creates a transducer that transforms a reducing function by applying a
function to each input and processing the resulting value, ignoring values
that are null.
|
static <A> ITransducer<A,A> |
keepIndexed(BiFunction<Long,A,A> f)
Creates a transducer that transforms a reducing function by applying a
function to each input and processing the resulting value, ignoring values
that are null.
|
static <A,B> ITransducer<A,B> |
map(Function<B,A> f)
Creates a transducer that transforms a reducing function by applying a mapping
function to each input.
|
static <A,B extends Iterable<A>,C> |
mapcat(Function<C,B> f)
Creates a transducer that transforms a reducing function using
a composition of map and cat.
|
static <A> ITransducer<Iterable<A>,A> |
partitionAll(int n)
Creates a transducer that transforms a reducing function that processes
iterables of input into a reducing function that processes individual inputs
by gathering series of inputs into partitions of a given size, only forwarding
them to the next reducing function when enough inputs have been accrued.
|
static <A,P> ITransducer<Iterable<A>,A> |
partitionBy(Function<A,P> f)
Creates a transducer that transforms a reducing function that processes
iterables of input into a reducing function that processes individual inputs
by gathering series of inputs for which the provided partitioning function returns
the same value, only forwarding them to the next reducing function when the value
the partitioning function returns for a given input is different from the value
returned for the previous input.
|
static <A> ITransducer<A,A> |
randomSample(Double prob)
Creates a transducer that transforms a reducing function such that
it has the specified probability of processing each input.
|
static <A> ITransducer<A,A> |
remove(Predicate<A> p)
Creates a transducer that transforms a reducing function by applying a
predicate to each input and not processing those inputs for which the
predicate is true.
|
static <A> ITransducer<A,A> |
replace(Map<A,A> smap)
Creates a transducer that transforms a reducing function such that
inputs that are keys in the provided map are replaced by the corresponding
value in the map.
|
static <A> ITransducer<A,A> |
take(long n)
Creates a transducer that transforms a reducing function such that
it only processes n inputs, then the reducing process stops.
|
static <A> ITransducer<A,A> |
takeNth(long n)
Creates a transducer that transforms a reducing function such that
it processes every nth input.
|
static <A> ITransducer<A,A> |
takeWhile(Predicate<A> p)
Creates a transducer that transforms a reducing function such that
it processes inputs as long as the provided predicate returns true.
|
static <R,A,B> R |
transduce(ITransducer<A,B> xf,
IReducingFunction<R,? super A> rf,
Iterable<B> input)
Reduces input using transformed reducing function.
|
static <R,A,B> R |
transduce(ITransducer<A,B> xf,
IStepFunction<R,? super A> rf,
R init,
Iterable<B> input)
Reduces input using transformed reducing function.
|
public static <R,T> IReducingFunction<R,? super T> completing(IStepFunction<R,? super T> sf)
R - the return type of the step function and reducing functionT - the input type of the step function and the reducing functionsf - The step function to convert to an IReducingFunction, if it is not one alreadypublic static <R,A,B> R transduce(ITransducer<A,B> xf, IReducingFunction<R,? super A> rf, Iterable<B> input)
R - return typeA - type of input expected by reducing functionB - type of input and type accepted by reducing function returned by transducerxf - a transducer (or composed transducers) that transforms the reducing functionrf - a reducing functioninput - the input to reducepublic static <R,A,B> R transduce(ITransducer<A,B> xf, IStepFunction<R,? super A> rf, R init, Iterable<B> input)
R - return typeA - type expected by reducing functionB - type of input and type accepted by reducing function returned by transducerxf - a transducer (or composed transducers) that transforms the reducing functionrf - a reducing functioninit - an initial value to start reducing processinput - the input to reducepublic static <R extends Collection<A>,A,B> R into(ITransducer<A,B> xf, R init, Iterable<B> input)
R - return typeA - type the collection containsB - type of input and type accepted by reducing function returned by transducerxf - a transducer (or composed transducers) that transforms the reducing functioninit - an initial collection to start reducing processinput - the input to put into the collectionpublic static <A,B,C> ITransducer<A,C> compose(ITransducer<B,C> left, ITransducer<A,B> right)
A - reducing function input typeB - reducing function input typeC - reducing function input typeleft - left hand transducerright - right hand transducerpublic static <A,B> ITransducer<A,B> map(Function<B,A> f)
A - input type of input reducing functionB - input type of output reducing functionf - a mapping function from one type to another (can be the same type)public static <A> ITransducer<A,A> filter(Predicate<A> p)
A - input type of input and output reducing functionsp - a predicate functionpublic static <A,B extends Iterable<A>> ITransducer<A,B> cat()
A - input type of input reducing functionB - input type of output reducing functionpublic static <A,B extends Iterable<A>,C> ITransducer<A,C> mapcat(Function<C,B> f)
A - input type of input reducing functionB - output type of output reducing function and iterable of input type
of input reducing functionC - input type of output reducing functionf - a mapping function from one type to another (can be the same type)public static <A> ITransducer<A,A> remove(Predicate<A> p)
A - input type of input and output reducing functionsp - a predicate functionpublic static <A> ITransducer<A,A> take(long n)
A - input type of input and output reducing functionsn - the number of inputs to processpublic static <A> ITransducer<A,A> takeWhile(Predicate<A> p)
A - input type of input and output reducing functionsp - a predicate used to test inputspublic static <A> ITransducer<A,A> drop(long n)
A - input type of input and output reducing functionsn - the number of inputs to skippublic static <A> ITransducer<A,A> dropWhile(Predicate<A> p)
A - input type of input and output reducing functionsp - a predicate used to test inputspublic static <A> ITransducer<A,A> takeNth(long n)
A - The input type of the input and output reducing functionsn - The frequence of inputs to process (e.g., 3 processes every third input).public static <A> ITransducer<A,A> replace(Map<A,A> smap)
A - the input type of the input and output reducing functionssmap - a map of replacement valuespublic static <A> ITransducer<A,A> keep(Function<A,A> f)
A - the input type of the input and output reducing functionsf - a function for processing inputspublic static <A> ITransducer<A,A> keepIndexed(BiFunction<Long,A,A> f)
A - the input type of the input and output reducing functionsf - a function for processing inputspublic static <A> ITransducer<A,A> dedupe()
A - the input type of the input and output reducing functionspublic static <A> ITransducer<A,A> randomSample(Double prob)
A - the input type of the input and output reducing functionsprob - the probability between expressed as a value between 0 and 1.public static <A,P> ITransducer<Iterable<A>,A> partitionBy(Function<A,P> f)
A - the input type of the input and output reducing functionsP - the type returned by the partitioning functionf - the partitioning functionpublic static <A> ITransducer<Iterable<A>,A> partitionAll(int n)
A - the input type of the input and output reducing functionsn - the size of each partitionCopyright © 2014. All rights reserved.