Package fj.data
Class Array.ImmutableProjection<A>
- java.lang.Object
-
- fj.data.Array.ImmutableProjection<A>
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ImmutableProjection(Array<A> a)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Array<A>
append(Array<A> aas)
Appends the given array to this array.<B> Array<B>
apply(Array<F<A,B>> lf)
Performs function application within an array (applicative functor pattern).<B> Array<B>
bind(F<A,Array<B>> f)
Binds the given function across each element of this array with a final join.Array<A>
filter(F<A,java.lang.Boolean> f)
Filters elements from this array by returning only elements which producetrue
when the given function is applied to them.<B> B
foldLeft(F<B,F<A,B>> f, B b)
Performs a left-fold reduction across this array.<B> B
foldRight(F<A,F<B,B>> f, B b)
Performs a right-fold reduction across this array.Unit
foreach(F<A,Unit> f)
Performs a side-effect for each element of this array.A
get(int index)
Returns the element at the given index if it exists, fails otherwise.boolean
isEmpty()
Returnstrue
is this array is empty,false
otherwise.boolean
isNotEmpty()
Returnsfalse
is this array is empty,true
otherwise.java.util.Iterator<A>
iterator()
Returns an iterator for this array.int
length()
Returns the length of this array.<B> Array<B>
map(F<A,B> f)
Maps the given function across this array.Array<A>
reverse()
Reverse this array in constant stack space.<B> Array<B>
sequence(Array<B> bs)
Performs a bind across each array element, but ignores the element value each time.java.util.Collection<A>
toCollection()
Projects an immutable collection of this array.<X> Either<X,A>
toEither(F0<X> x)
Returns an either projection of this array; the given argument inLeft
if empty, or the first element inRight
.List<A>
toList()
Returns a list projection of this array.Option<A>
toOption()
Returns an option projection of this array;None
if empty, or the first element inSome
.Stream<A>
toStream()
Returns a stream projection of this array.
-
-
-
Method Detail
-
iterator
public java.util.Iterator<A> iterator()
Returns an iterator for this array. This method exists to permit the use in afor
-each loop.- Specified by:
iterator
in interfacejava.lang.Iterable<A>
- Returns:
- A iterator for this array.
-
get
public A get(int index)
Returns the element at the given index if it exists, fails otherwise.- Parameters:
index
- The index at which to get the element to return.- Returns:
- The element at the given index if it exists, fails otherwise.
-
length
public int length()
Returns the length of this array.- Returns:
- The length of this array.
-
isEmpty
public boolean isEmpty()
Returnstrue
is this array is empty,false
otherwise.- Returns:
true
is this array is empty,false
otherwise.
-
isNotEmpty
public boolean isNotEmpty()
Returnsfalse
is this array is empty,true
otherwise.- Returns:
false
is this array is empty,true
otherwise.
-
toOption
public Option<A> toOption()
Returns an option projection of this array;None
if empty, or the first element inSome
.- Returns:
- An option projection of this array.
-
toEither
public <X> Either<X,A> toEither(F0<X> x)
Returns an either projection of this array; the given argument inLeft
if empty, or the first element inRight
.- Parameters:
x
- The value to return in left if this array is empty.- Returns:
- An either projection of this array.
-
toList
public List<A> toList()
Returns a list projection of this array.- Returns:
- A list projection of this array.
-
toStream
public Stream<A> toStream()
Returns a stream projection of this array.- Returns:
- A stream projection of this array.
-
map
public <B> Array<B> map(F<A,B> f)
Maps the given function across this array.- Parameters:
f
- The function to map across this array.- Returns:
- A new array after the given function has been applied to each element.
-
filter
public Array<A> filter(F<A,java.lang.Boolean> f)
Filters elements from this array by returning only elements which producetrue
when the given function is applied to them.- Parameters:
f
- The predicate function to filter on.- Returns:
- A new array whose elements all match the given predicate.
-
foreach
public Unit foreach(F<A,Unit> f)
Performs a side-effect for each element of this array.- Parameters:
f
- The side-effect to perform for the given element.- Returns:
- The unit value.
-
foldRight
public <B> B foldRight(F<A,F<B,B>> f, B b)
Performs a right-fold reduction across this array. This function uses O(length) stack space.- Parameters:
f
- The function to apply on each element of the array.b
- The beginning value to start the application from.- Returns:
- The final result after the right-fold reduction.
-
foldLeft
public <B> B foldLeft(F<B,F<A,B>> f, B b)
Performs a left-fold reduction across this array. This function runs in constant space.- Parameters:
f
- The function to apply on each element of the array.b
- The beginning value to start the application from.- Returns:
- The final result after the left-fold reduction.
-
bind
public <B> Array<B> bind(F<A,Array<B>> f)
Binds the given function across each element of this array with a final join.- Parameters:
f
- The function to apply to each element of this array.- Returns:
- A new array after performing the map, then final join.
-
sequence
public <B> Array<B> sequence(Array<B> bs)
Performs a bind across each array element, but ignores the element value each time.- Parameters:
bs
- The array to apply in the final join.- Returns:
- A new array after the final join.
-
apply
public <B> Array<B> apply(Array<F<A,B>> lf)
Performs function application within an array (applicative functor pattern).- Parameters:
lf
- The array of functions to apply.- Returns:
- A new array after applying the given array of functions through this array.
-
reverse
public Array<A> reverse()
Reverse this array in constant stack space.- Returns:
- A new array that is the reverse of this one.
-
append
public Array<A> append(Array<A> aas)
Appends the given array to this array.- Parameters:
aas
- The array to append to this one.- Returns:
- A new array that has appended the given array.
-
toCollection
public java.util.Collection<A> toCollection()
Projects an immutable collection of this array.- Returns:
- An immutable collection of this array.
-
-