Class Array<A>
java.lang.Object
fj.data.Array<A>
- All Implemented Interfaces:
Iterable<A>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classProjects an array by providing only operations which do not mutate. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the given array to this array.<B> Array<B> Performs function application within an array (applicative functor pattern).Object[]array()Returns a copy of the underlying primitive array.static <A> Array<A> array(A... as) Constructs an array from the given elements.A[]Returns a copy of the underlying primitive array.static <A> Array<A> arrayArray(A... as) Returns a copy of the underlying primitive array.Projects an unmodifiable list view of this array.<B,C> Array <C> Binds the given function across each element of this array and the given array with a final join.<B,C> Array <C> Binds the given function across each element of this array and the given array with a final join.<B> Array<B> Binds the given function across each element of this array with a final join.static <T> T[]copyOf(T[] a, int len) static <T,U> T[] static char[]copyOfRange(char[] a, int from, int to) static <A> Array<A> empty()Returns an empty array.booleanbooleanReturnstrueif the predicate holds for at least one of the elements of this array,falseotherwise (falsefor the empty array).Filters elements from this array by returning only elements which producetruewhen the given function is applied to them.Finds the first occurrence of an element that matches the given predicate or no value if no elements match.<B> BPerforms a left-fold reduction across this array.<B> BPerforms a left-fold reduction across this array.<B> BPerforms a right-fold reduction across this array.<B> BPerforms a right-fold reduction across this array.booleanReturnstrueif the predicate holds for all of the elements of this array,falseotherwise (truefor the empty array).Performs a side-effect for each element of this array.voidforeachDoEffect(Effect1<A> f) Performs a side-effect for each element of this array.get(int index) Returns the element at the given index if it exists, fails otherwise.inthashCode()booleanisEmpty()Returnstrueis this array is empty,falseotherwise.booleanReturnsfalseis this array is empty,trueotherwise.static <A> Array<A> iterableArray(Iterable<A> i) Takes the given iterable to an array.iterator()Returns an iterator for this array.static <A> Array<A> iteratorArray(Iterator<A> i) Creates an Array from the iterator.join()A first-class version of joinstatic <A> Array<A> Joins the given array of arrays using a bind operation.intlength()Returns the length of this array.map()First-class map function for Arrays.<B> Array<B> Maps the given function across this array.(package private) static <A> Array<A> Unsafe package-private constructor.range(int from, int to) Returns an array of integers from the givenfromvalue (inclusive) to the giventovalue (exclusive).reverse()Reverse this array in constant stack space.<B> Array<B> Performs a fold left accummulating and returns an array of the intermediate results.<B> Array<B> Performs a left-fold accummulating and returns an array of the intermediate results.Performs a left-fold accummulating using first array element as a starting value and returns an array of the intermediate results.Performs a left-fold accummulating using first array element as a starting value and returns an array of the intermediate results.<B> Array<B> Performs a right-fold accummulating and returns an array of the intermediate results.<B> Array<B> Performs a right-fold accummulating and returns an array of the intermediate results.Performs a right-fold accummulating using last array element as a starting value and returns an array of the intermediate results.scanRight1(F2<A, A, A> f) Performs a right-fold accummulating using last array element as a starting value and returns an array of the intermediate results.<B> Array<B> Performs a bind across each array element, but ignores the element value each time.Sets the element at the given index to the given value.static <A> Array<A> single(A a) Constructs a singleton array.Projects an immutable collection of this array.Returns an either projection of this array; the given argument inLeftif empty, or the first element inRight.Returns a java.util.ArrayList projection of this array.toList()Returns a list projection of this array.toOption()Returns an option projection of this array;Noneif empty, or the first element inSome.toStream()Returns a stream projection of this array.toString()Transforms an array of pairs into an array of first components and an array of second components.wrap()First-class wrapper function for arrays.Zips this array with the given array to produce an array of pairs.zipIndex()Zips this array with the index of its element as a pair.<B,C> Array <C> Zips this array with the given array using the given function to produce a new array.<B,C> Array <C> Zips this array with the given array using the given function to produce a new array.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
a
-
-
Constructor Details
-
Array
-
-
Method Details
-
iterator
-
get
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.
-
hashCode
-
set
-
length
public int length()Returns the length of this array.- Returns:
- The length of this array.
-
immutable
-
isEmpty
public boolean isEmpty()Returnstrueis this array is empty,falseotherwise.- Returns:
trueis this array is empty,falseotherwise.
-
isNotEmpty
public boolean isNotEmpty()Returnsfalseis this array is empty,trueotherwise.- Returns:
falseis this array is empty,trueotherwise.
-
array
-
array
Returns a copy of the underlying primitive array.- Returns:
- A copy of the underlying primitive array;
-
toOption
-
toEither
-
toList
-
toStream
-
toString
-
map
-
filter
-
foreach
-
foreachDoEffect
-
foldRight
Performs a right-fold reduction across this array. This function runs in constant 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.
-
foldRight
Performs a right-fold reduction across this array. This function runs in constant 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
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.
-
foldLeft
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.
-
scanLeft
Performs a fold left accummulating and returns an array of the intermediate results. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (initial value/previous result and next array element)b- The beginning value to start the application from.- Returns:
- The array containing all intermediate results of the left-fold reduction.
-
scanLeft
Performs a left-fold accummulating and returns an array of the intermediate results. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (initial value/previous result and next array element)b- The beginning value to start the application from.- Returns:
- The array containing all intermediate results of the left-fold reduction.
-
scanLeft1
Performs a left-fold accummulating using first array element as a starting value and returns an array of the intermediate results. It will fail for empty arrays. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (next array element and first array element/previous result)- Returns:
- The array containing all intermediate results of the left-fold reduction.
-
scanLeft1
Performs a left-fold accummulating using first array element as a starting value and returns an array of the intermediate results. It will fail for empty arrays. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (next array element and first array element/previous result)- Returns:
- The array containing all intermediate results of the left-fold reduction.
-
scanRight
Performs a right-fold accummulating and returns an array of the intermediate results. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (previous array element and initial value/previous result)b- The beginning value to start the application from.- Returns:
- The array containing all intermediate results of the right-fold reduction.
-
scanRight
Performs a right-fold accummulating and returns an array of the intermediate results. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (previous array element and initial value/previous result)b- The beginning value to start the application from.- Returns:
- The array containing all intermediate results of the right-fold reduction.
-
scanRight1
Performs a right-fold accummulating using last array element as a starting value and returns an array of the intermediate results. It will fail for empty arrays. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (previous array element and last array element/previous result)- Returns:
- The array containing all intermediate results of the right-fold reduction.
-
scanRight1
Performs a right-fold accummulating using last array element as a starting value and returns an array of the intermediate results. It will fail for empty arrays. This function runs in constant stack space.- Parameters:
f- The function to apply on each argument pair (previous array element and last array element/previous result)- Returns:
- The array containing all intermediate results of the right-fold reduction.
-
bind
-
sequence
-
bind
Binds the given function across each element of this array and the given array with a final join.- Parameters:
sb- A given array to bind the given function with.f- The function to apply to each element of this array and the given array.- Returns:
- A new array after performing the map, then final join.
-
bind
Binds the given function across each element of this array and the given array with a final join.- Parameters:
sb- A given array to bind the given function with.f- The function to apply to each element of this array and the given array.- Returns:
- A new array after performing the map, then final join.
-
apply
-
reverse
-
append
-
empty
-
array
Constructs an array from the given elements.- Parameters:
as- The elements to construct the array with.- Returns:
- A new array of the given elements.
-
mkArray
-
single
Constructs a singleton array.- Parameters:
a- The element to put in the array.- Returns:
- An array with the given single element.
-
wrap
-
map
-
join
-
join
-
forall
Returnstrueif the predicate holds for all of the elements of this array,falseotherwise (truefor the empty array).- Parameters:
f- the predicate function to test on each element of this array.- Returns:
trueif the predicate holds for all of the elements of this array,falseotherwise.
-
exists
Returnstrueif the predicate holds for at least one of the elements of this array,falseotherwise (falsefor the empty array).- Parameters:
f- the predicate function to test on the elements of this array.- Returns:
trueif the predicate holds for at least one of the elements of this array.
-
equals
-
find
Finds the first occurrence of an element that matches the given predicate or no value if no elements match.- Parameters:
f- The predicate function to test on elements of this array.- Returns:
- The first occurrence of an element that matches the given predicate or no value if no elements match.
-
range
Returns an array of integers from the givenfromvalue (inclusive) to the giventovalue (exclusive).- Parameters:
from- The minimum value for the array (inclusive).to- The maximum value for the array (exclusive).- Returns:
- An array of integers from the given
fromvalue (inclusive) to the giventovalue (exclusive).
-
zipWith
Zips this array with the given array using the given function to produce a new array. If this array and the given array have different lengths, then the longer array is normalised so this function never fails.- Parameters:
bs- The array to zip this array with.f- The function to zip this array and the given array with.- Returns:
- A new array with a length the same as the shortest of this array and the given array.
-
zipWith
Zips this array with the given array using the given function to produce a new array. If this array and the given array have different lengths, then the longer array is normalised so this function never fails.- Parameters:
bs- The array to zip this array with.f- The function to zip this array and the given array with.- Returns:
- A new array with a length the same as the shortest of this array and the given array.
-
zip
Zips this array with the given array to produce an array of pairs. If this array and the given array have different lengths, then the longer array is normalised so this function never fails.- Parameters:
bs- The array to zip this array with.- Returns:
- A new array with a length the same as the shortest of this array and the given array.
-
zipIndex
-
toCollection
Projects an immutable collection of this array.- Returns:
- An immutable collection of this array.
-
asJavaList
-
toJavaList
-
iterableArray
-
iteratorArray
-
arrayArray
Returns a copy of the underlying primitive array. Equivalent to array(A...)- Returns:
- A copy of the underlying primitive array.
-
unzip
-
copyOf
-
copyOf
public static <T> T[] copyOf(T[] a, int len) -
copyOfRange
public static char[] copyOfRange(char[] a, int from, int to)
-