|
Copyright Tony Morris 2008 This software is released under an open source BSD licence. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectfj.data.Array<A>
public final class Array<A>
Provides an interface to arrays.
| Nested Class Summary | |
|---|---|
class |
Array.ImmutableProjection<A>
Projects an array by providing only operations which do not mutate. |
| Method Summary | ||
|---|---|---|
Array<A> |
append(Array<A> aas)
Appends the given array to this array. |
|
|
apply(Array<F<A,B>> lf)
Performs function application within an array (applicative functor pattern). |
|
A[] |
array()
Returns the underlying primitive array. |
|
static
|
array(A... a)
Constructs an array from the given elements. |
|
|
bind(F<A,Array<B>> f)
Binds the given function across each element of this array with a final join. |
|
static
|
empty()
Returns an empty array. |
|
boolean |
exists(F<A,Boolean> f)
Returns true if the predicate holds for at least one of the elements of this
array, false otherwise (false for the empty array). |
|
Array<A> |
filter(F<A,Boolean> f)
Filters elements from this array by returning only elements which produce true
when the given function is applied to them. |
|
Option<A> |
find(F<A,Boolean> f)
Finds the first occurrence of an element that matches the given predicate or no value if no elements match. |
|
|
foldLeft(F<B,F<A,B>> f,
B b)
Performs a left-fold reduction across this array. |
|
|
foldLeft(F2<B,A,B> f,
B b)
Performs a left-fold reduction across this array. |
|
|
foldRight(F<A,F<B,B>> f,
B b)
Performs a right-fold reduction across this array. |
|
|
foldRight(F2<A,B,B> f,
B b)
Performs a right-fold reduction across this array. |
|
boolean |
forall(F<A,Boolean> f)
Returns true if the predicate holds for all of the elements of this array,
false otherwise (true for the empty array). |
|
void |
foreach(Effect<A> f)
Performs a side-effect for each element of 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. |
|
Array.ImmutableProjection<A> |
immutable()
|
|
boolean |
isEmpty()
Returns true is this array is empty, false otherwise. |
|
boolean |
isNotEmpty()
Returns false is this array is empty, true otherwise. |
|
static
|
iterableArray(Iterable<A> i)
Takes the given iterable to an array. |
|
Iterator<A> |
iterator()
Returns an iterator for this array. |
|
static
|
join()
A first-class version of join |
|
static
|
join(Array<Array<A>> o)
Joins the given array of arrays using a bind operation. |
|
int |
length()
Returns the length of this array. |
|
|
map(F<A,B> f)
Maps the given function across this array. |
|
static Array<Integer> |
range(int from,
int to)
Returns an array of integers from the given from value (inclusive) to the given
to value (exclusive). |
|
Array<A> |
reverse()
Reverse this array in constant stack space. |
|
|
sequence(Array<B> bs)
Performs a bind across each array element, but ignores the element value each time. |
|
Unit |
set(int index,
A a)
Sets the element at the given index to the given value. |
|
Collection<A> |
toCollection()
Projects an immutable collection of this array. |
|
|
toEither(P1<X> x)
Returns an either projection of this array; the given argument in Left if empty,
or the first element in Right. |
|
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 in
Some. |
|
Stream<A> |
toStream()
Returns a stream projection of this array. |
|
static
|
unzip(Array<P2<A,B>> xs)
Transforms an array of pairs into an array of first components and an array of second components. |
|
|
zip(Array<B> bs)
Zips this array with the given array to produce an array of pairs. |
|
Array<P2<A,Integer>> |
zipIndex()
Zips this array with the index of its element as a pair. |
|
|
zipWith(Array<B> bs,
F<A,F<B,C>> f)
Zips this array with the given array using the given function to produce a new array. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public Iterator<A> iterator()
for-each loop.
iterator in interface Iterable<A>public A get(int index)
index - The index at which to get the element to return.
public Unit set(int index,
A a)
index - The index at which to set the given value.a - The value to set at the given index.
public int length()
public Array.ImmutableProjection<A> immutable()
public boolean isEmpty()
true is this array is empty, false otherwise.
true is this array is empty, false otherwise.public boolean isNotEmpty()
false is this array is empty, true otherwise.
false is this array is empty, true otherwise.public A[] array()
public Option<A> toOption()
None if empty, or the first element in
Some.
public <X> Either<X,A> toEither(P1<X> x)
Left if empty,
or the first element in Right.
x - The value to return in left if this array is empty.
public List<A> toList()
public Stream<A> toStream()
public <B> Array<B> map(F<A,B> f)
f - The function to map across this array.
public Array<A> filter(F<A,Boolean> f)
true
when the given function is applied to them.
f - The predicate function to filter on.
public Unit foreach(F<A,Unit> f)
f - The side-effect to perform for the given element.
public void foreach(Effect<A> f)
f - The side-effect to perform for the given element.
public <B> B foldRight(F<A,F<B,B>> f,
B b)
f - The function to apply on each element of the array.b - The beginning value to start the application from.
public <B> B foldRight(F2<A,B,B> f,
B b)
f - The function to apply on each element of the array.b - The beginning value to start the application from.
public <B> B foldLeft(F<B,F<A,B>> f,
B b)
f - The function to apply on each element of the array.b - The beginning value to start the application from.
public <B> B foldLeft(F2<B,A,B> f,
B b)
f - The function to apply on each element of the array.b - The beginning value to start the application from.
public <B> Array<B> bind(F<A,Array<B>> f)
f - The function to apply to each element of this array.
public <B> Array<B> sequence(Array<B> bs)
bs - The array to apply in the final join.
public <B> Array<B> apply(Array<F<A,B>> lf)
lf - The array of functions to apply.
public Array<A> reverse()
public Array<A> append(Array<A> aas)
aas - The array to append to this one.
public static <A> Array<A> empty()
public static <A> Array<A> array(A... a)
a - The elements to construct the array with.
public static <A> Array<A> join(Array<Array<A>> o)
o - The array of arrays to join.
public static <A> F<Array<Array<A>>,Array<A>> join()
public boolean forall(F<A,Boolean> f)
true if the predicate holds for all of the elements of this array,
false otherwise (true for the empty array).
f - the predicate function to test on each element of this array.
true if the predicate holds for all of the elements of this array,
false otherwise.public boolean exists(F<A,Boolean> f)
true if the predicate holds for at least one of the elements of this
array, false otherwise (false for the empty array).
f - the predicate function to test on the elements of this array.
true if the predicate holds for at least one of the elements of this
array.public Option<A> find(F<A,Boolean> f)
f - The predicate function to test on elements of this array.
public static Array<Integer> range(int from,
int to)
from value (inclusive) to the given
to value (exclusive).
from - The minimum value for the array (inclusive).to - The maximum value for the array (exclusive).
from value (inclusive) to the given
to value (exclusive).
public <B,C> Array<C> zipWith(Array<B> bs,
F<A,F<B,C>> f)
bs - The array to zip this array with.f - The function to zip this array and the given array with.
public <B> Array<P2<A,B>> zip(Array<B> bs)
bs - The array to zip this array with.
public Array<P2<A,Integer>> zipIndex()
public Collection<A> toCollection()
public static <A> Array<A> iterableArray(Iterable<A> i)
i - The iterable to take to an array.
public static <A,B> P2<Array<A>,Array<B>> unzip(Array<P2<A,B>> xs)
xs - The array of pairs to transform.
|
Copyright Tony Morris 2008 This software is released under an open source BSD licence. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||