enhanced Array / Promise in ees6 candy

This commit is contained in:
Louis Grignon 2018-10-07 18:19:25 +02:00
parent 10321a0cf0
commit 58efd32efc
2 changed files with 269 additions and 289 deletions

View File

@ -7,14 +7,13 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
public native T[] toArray();
/**
* Gets or sets the length of the array. This is a number one higher than
* the highest element defined in an array.
* Gets or sets the length of the array. This is a number one higher than the
* highest element defined in an array.
*/
public int length;
/**
* Appends new elements to an array, and returns the new length of the
* array.
* Appends new elements to an array, and returns the new length of the array.
*
* @param items
* New elements of the Array.
@ -55,9 +54,9 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* string.
*
* @param separator
* A string used to separate one element of an array from the
* next in the resulting String. If omitted, the array elements
* are separated with a comma.
* A string used to separate one element of an array from the next in
* the resulting String. If omitted, the array elements are separated
* with a comma.
*/
native public String join(java.lang.String separator);
@ -66,9 +65,9 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* string.
*
* @param separator
* A string used to separate one element of an array from the
* next in the resulting String. If omitted, the array elements
* are separated with a comma.
* A string used to separate one element of an array from the next in
* the resulting String. If omitted, the array elements are separated
* with a comma.
*/
native public String join(String separator);
@ -97,8 +96,8 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
*
* @param compareFn
* The name of the function used to determine the order of the
* elements. If omitted, the elements are sorted in ascending,
* ASCII character order.
* elements. If omitted, the elements are sorted in ascending, ASCII
* character order.
*/
native public Array<T> sort(java.util.function.BiFunction<T, T, Integer> compareFn);
@ -107,8 +106,8 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* their place, returning the deleted elements.
*
* @param start
* The zero-based location in the array from which to start
* removing elements.
* The zero-based location in the array from which to start removing
* elements.
*/
native public Array<T> splice(int start);
@ -117,8 +116,8 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* their place, returning the deleted elements.
*
* @param start
* The zero-based location in the array from which to start
* removing elements.
* The zero-based location in the array from which to start removing
* elements.
* @param deleteCount
* The number of elements to remove.
* @param items
@ -147,8 +146,7 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public int indexOf(T searchElement, int fromIndex);
/**
* Returns the index of the last occurrence of a specified value in an
* array.
* Returns the index of the last occurrence of a specified value in an array.
*
* @param searchElement
* The value to locate in the array.
@ -159,53 +157,34 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public int lastIndexOf(T searchElement, int fromIndex);
/**
* Determines whether all the members of an array satisfy the specified
* test.
* Determines whether all the members of an array satisfy the specified test.
*
* @param callbackfn
* A function that accepts up to three arguments. The every
* method calls the callbackfn function for each element in
* array1 until the callbackfn returns false, or until the end of
* the array.
* A function that accepts up to three arguments. The every method
* calls the callbackfn function for each element in array1 until the
* callbackfn returns false, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public java.lang.Boolean every(
jsweet.util.function.TriFunction<T, Double, Array<T>, java.lang.Boolean> callbackfn, java.lang.Object thisArg);
jsweet.util.function.TriFunction<T, Double, Array<T>, java.lang.Boolean> callbackfn,
java.lang.Object thisArg);
/**
* Determines whether all the members of an array satisfy the specified
* test.
* Determines whether all the members of an array satisfy the specified test.
*
* @param callbackfn
* A function that accepts up to three arguments. The every
* method calls the callbackfn function for each element in
* array1 until the callbackfn returns false, or until the end of
* the array.
* A function that accepts up to three arguments. The every method
* calls the callbackfn function for each element in array1 until the
* callbackfn returns false, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public java.lang.Boolean every(
java.util.function.Function<T, java.lang.Boolean> callbackfn, java.lang.Object thisArg);
/**
* Determines whether the specified callback function returns true for any
* element of an array.
*
* @param callbackfn
* A function that accepts up to three arguments. The some method
* calls the callbackfn function for each element in array1 until
* the callbackfn returns true, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
*/
native public java.lang.Boolean some(jsweet.util.function.TriFunction<T, Double, Array<T>, java.lang.Boolean> callbackfn,
native public java.lang.Boolean every(java.util.function.Function<T, java.lang.Boolean> callbackfn,
java.lang.Object thisArg);
/**
@ -214,12 +193,29 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
*
* @param callbackfn
* A function that accepts up to three arguments. The some method
* calls the callbackfn function for each element in array1 until
* the callbackfn returns true, or until the end of the array.
* calls the callbackfn function for each element in array1 until the
* callbackfn returns true, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public java.lang.Boolean some(
jsweet.util.function.TriFunction<T, Double, Array<T>, java.lang.Boolean> callbackfn,
java.lang.Object thisArg);
/**
* Determines whether the specified callback function returns true for any
* element of an array.
*
* @param callbackfn
* A function that accepts up to three arguments. The some method
* calls the callbackfn function for each element in array1 until the
* callbackfn returns true, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public java.lang.Boolean some(java.util.function.Function<T, java.lang.Boolean> callbackfn,
java.lang.Object thisArg);
@ -228,57 +224,57 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* Performs the specified action for each element in an array.
*
* @param callbackfn
* A function that accepts up to three arguments. forEach calls
* the callbackfn function one time for each element in the
* array.
* A function that accepts up to three arguments. forEach calls the
* callbackfn function one time for each element in the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public void forEach(jsweet.util.function.TriConsumer<T, Integer, Array<T>> callbackfn, java.lang.Object thisArg);
native public void forEach(jsweet.util.function.TriConsumer<T, Integer, Array<T>> callbackfn,
java.lang.Object thisArg);
/**
* Performs the specified action for each element in an array.
*
* @param callbackfn
* A function that accepts up to three arguments. forEach calls
* the callbackfn function one time for each element in the
* array.
* A function that accepts up to three arguments. forEach calls the
* callbackfn function one time for each element in the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public void forEach(java.util.function.Consumer<T> callbackfn, java.lang.Object thisArg);
/**
* Calls a defined callback function on each element of an array, and
* returns an array that contains the results.
* Calls a defined callback function on each element of an array, and returns an
* array that contains the results.
*
* @param callbackfn
* A function that accepts up to three arguments. The map method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public <U> Array<U> map(jsweet.util.function.TriFunction<T, Integer, Array<T>, U> callbackfn, java.lang.Object thisArg);
native public <U> Array<U> map(jsweet.util.function.TriFunction<T, Integer, Array<T>, U> callbackfn,
java.lang.Object thisArg);
/**
* Calls a defined callback function on each element of an array, and
* returns an array that contains the results.
* Calls a defined callback function on each element of an array, and returns an
* array that contains the results.
*
* @param callbackfn
* A function that accepts up to three arguments. The map method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public <U> Array<U> map(java.util.function.Function<T, U> callbackfn, java.lang.Object thisArg);
@ -287,13 +283,13 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* callback function.
*
* @param callbackfn
* A function that accepts up to three arguments. The filter
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to three arguments. The filter method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public Array<T> filter(jsweet.util.function.TriFunction<T, Integer, Array<T>, java.lang.Boolean> callbackfn,
java.lang.Object thisArg);
@ -303,99 +299,95 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* callback function.
*
* @param callbackfn
* A function that accepts up to three arguments. The filter
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to three arguments. The filter method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public Array<T> filter(java.util.function.Function<T, java.lang.Boolean> callbackfn,
java.lang.Object thisArg);
/**
* Calls the specified callback function for all the elements in an array.
* The return value of the callback function is the accumulated result, and
* is provided as an argument in the next call to the callback function.
* Calls the specified callback function for all the elements in an array. The
* return value of the callback function is the accumulated result, and is
* provided as an argument in the next call to the callback function.
*
* @param callbackfn
* A function that accepts up to four arguments. The reduce
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to four arguments. The reduce method
* calls the callbackfn function one time for each element in the
* array.
* @param initialValue
* If initialValue is specified, it is used as the initial value
* to start the accumulation. The first call to the callbackfn
* function provides this value as an argument instead of an
* array value.
* If initialValue is specified, it is used as the initial value to
* start the accumulation. The first call to the callbackfn function
* provides this value as an argument instead of an array value.
*/
@jsweet.lang.Name("reduce")
native public T reduceCallbackfnFunction4(Function4<T, T, Double, Array<T>, T> callbackfn,
InitialValueT<T> initialValue);
/**
* Calls the specified callback function for all the elements in an array.
* The return value of the callback function is the accumulated result, and
* is provided as an argument in the next call to the callback function.
* Calls the specified callback function for all the elements in an array. The
* return value of the callback function is the accumulated result, and is
* provided as an argument in the next call to the callback function.
*
* @param callbackfn
* A function that accepts up to four arguments. The reduce
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to four arguments. The reduce method
* calls the callbackfn function one time for each element in the
* array.
* @param initialValue
* If initialValue is specified, it is used as the initial value
* to start the accumulation. The first call to the callbackfn
* function provides this value as an argument instead of an
* array value.
* If initialValue is specified, it is used as the initial value to
* start the accumulation. The first call to the callbackfn function
* provides this value as an argument instead of an array value.
*/
@jsweet.lang.Name("reduce")
native public <U> U reduceCallbackfnUUFunction4(Function4<U, T, Double, Array<T>, U> callbackfn,
InitialValueU<U> initialValue);
U initialValue);
/**
* Calls the specified callback function for all the elements in an array,
* in descending order. The return value of the callback function is the
* accumulated result, and is provided as an argument in the next call to
* the callback function.
* Calls the specified callback function for all the elements in an array, in
* descending order. The return value of the callback function is the
* accumulated result, and is provided as an argument in the next call to the
* callback function.
*
* @param callbackfn
* A function that accepts up to four arguments. The reduceRight
* method calls the callbackfn function one time for each element
* in the array.
* method calls the callbackfn function one time for each element in
* the array.
* @param initialValue
* If initialValue is specified, it is used as the initial value
* to start the accumulation. The first call to the callbackfn
* function provides this value as an argument instead of an
* array value.
* If initialValue is specified, it is used as the initial value to
* start the accumulation. The first call to the callbackfn function
* provides this value as an argument instead of an array value.
*/
@jsweet.lang.Name("reduceRight")
native public T reduceRightCallbackfnFunction4(Function4<T, T, Double, Array<T>, T> callbackfn,
InitialValueT<T> initialValue);
/**
* Calls the specified callback function for all the elements in an array,
* in descending order. The return value of the callback function is the
* accumulated result, and is provided as an argument in the next call to
* the callback function.
* Calls the specified callback function for all the elements in an array, in
* descending order. The return value of the callback function is the
* accumulated result, and is provided as an argument in the next call to the
* callback function.
*
* @param callbackfn
* A function that accepts up to four arguments. The reduceRight
* method calls the callbackfn function one time for each element
* in the array.
* method calls the callbackfn function one time for each element in
* the array.
* @param initialValue
* If initialValue is specified, it is used as the initial value
* to start the accumulation. The first call to the callbackfn
* function provides this value as an argument instead of an
* array value.
* If initialValue is specified, it is used as the initial value to
* start the accumulation. The first call to the callbackfn function
* provides this value as an argument instead of an array value.
*/
@jsweet.lang.Name("reduceRight")
native public <U> U reduceRightCallbackfnUUFunction4(Function4<U, T, Double, Array<T>, U> callbackfn,
InitialValueU<U> initialValue);
U initialValue);
native public T $get(int n);
native public T $set(int n, T value);
public Array(int arrayLength) {
}
@ -426,66 +418,60 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public IterableIterator<T> values();
/**
* Returns the value of the first element in the array where predicate is
* true, and undefined otherwise.
* Returns the value of the first element in the array where predicate is true,
* and undefined otherwise.
*
* @param predicate
* find calls predicate once for each element of the array, in
* ascending order, until it finds one where predicate returns
* true. If such an element is found, find immediately returns
* that element value. Otherwise, find returns undefined.
* ascending order, until it finds one where predicate returns true.
* If such an element is found, find immediately returns that element
* value. Otherwise, find returns undefined.
* @param thisArg
* If provided, it will be used as the this value for each
* invocation of predicate. If it is not provided, undefined is
* used instead.
* If provided, it will be used as the this value for each invocation
* of predicate. If it is not provided, undefined is used instead.
*/
native public T find(jsweet.util.function.TriFunction<T, Integer, Array<T>, java.lang.Boolean> predicate,
java.lang.Object thisArg);
/**
* Returns the value of the first element in the array where predicate is
* true, and undefined otherwise.
* Returns the value of the first element in the array where predicate is true,
* and undefined otherwise.
*
* @param predicate
* find calls predicate once for each element of the array, in
* ascending order, until it finds one where predicate returns
* true. If such an element is found, find immediately returns
* that element value. Otherwise, find returns undefined.
* ascending order, until it finds one where predicate returns true.
* If such an element is found, find immediately returns that element
* value. Otherwise, find returns undefined.
* @param thisArg
* If provided, it will be used as the this value for each
* invocation of predicate. If it is not provided, undefined is
* used instead.
* If provided, it will be used as the this value for each invocation
* of predicate. If it is not provided, undefined is used instead.
*/
native public T find(java.util.function.Function<T, java.lang.Boolean> predicate,
java.lang.Object thisArg);
native public T find(java.util.function.Function<T, java.lang.Boolean> predicate, java.lang.Object thisArg);
/**
* Returns the index of the first element in the array where predicate is
* true, and undefined otherwise.
* Returns the index of the first element in the array where predicate is true,
* and undefined otherwise.
*
* @param predicate
* find calls predicate once for each element of the array, in
* ascending order, until it finds one where predicate returns
* true. If such an element is found, find immediately returns
* that element value. Otherwise, find returns undefined.
* ascending order, until it finds one where predicate returns true.
* If such an element is found, find immediately returns that element
* value. Otherwise, find returns undefined.
* @param thisArg
* If provided, it will be used as the this value for each
* invocation of predicate. If it is not provided, undefined is
* used instead.
* If provided, it will be used as the this value for each invocation
* of predicate. If it is not provided, undefined is used instead.
*/
native public int findIndex(java.util.function.Function<T, java.lang.Boolean> predicate,
java.lang.Object thisArg);
native public int findIndex(java.util.function.Function<T, java.lang.Boolean> predicate, java.lang.Object thisArg);
/**
* Returns the this object after filling the section identified by start and
* end with value
* Returns the this object after filling the section identified by start and end
* with value
*
* @param value
* value to fill array section with
* @param start
* index to start filling the array at. If start is negative, it
* is treated as length+start where length is the length of the
* array.
* index to start filling the array at. If start is negative, it is
* treated as length+start where length is the length of the array.
* @param end
* index to stop filling the array at. If end is negative, it is
* treated as length+end.
@ -493,18 +479,18 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public Array<T> fill(T value, int start, int end);
/**
* Returns the this object after copying a section of the array identified
* by start and end to the same array starting at position target
* Returns the this object after copying a section of the array identified by
* start and end to the same array starting at position target
*
* @param target
* If target is negative, it is treated as length+target where
* length is the length of the array.
* If target is negative, it is treated as length+target where length
* is the length of the array.
* @param start
* If start is negative, it is treated as length+start. If end is
* negative, it is treated as length+end.
* @param end
* If not specified, length of the this object is used as its
* default value.
* If not specified, length of the this object is used as its default
* value.
*/
native public Array<T> copyWithin(int target, int start, int end);
@ -513,9 +499,9 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* string.
*
* @param separator
* A string used to separate one element of an array from the
* next in the resulting String. If omitted, the array elements
* are separated with a comma.
* A string used to separate one element of an array from the next in
* the resulting String. If omitted, the array elements are separated
* with a comma.
*/
native public String join();
@ -544,8 +530,8 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
*
* @param compareFn
* The name of the function used to determine the order of the
* elements. If omitted, the elements are sorted in ascending,
* ASCII character order.
* elements. If omitted, the elements are sorted in ascending, ASCII
* character order.
*/
native public Array<T> sort();
@ -561,8 +547,7 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public int indexOf(T searchElement);
/**
* Returns the index of the last occurrence of a specified value in an
* array.
* Returns the index of the last occurrence of a specified value in an array.
*
* @param searchElement
* The value to locate in the array.
@ -573,18 +558,16 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public int lastIndexOf(T searchElement);
/**
* Determines whether all the members of an array satisfy the specified
* test.
* Determines whether all the members of an array satisfy the specified test.
*
* @param callbackfn
* A function that accepts up to three arguments. The every
* method calls the callbackfn function for each element in
* array1 until the callbackfn returns false, or until the end of
* the array.
* A function that accepts up to three arguments. The every method
* calls the callbackfn function for each element in array1 until the
* callbackfn returns false, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public java.lang.Boolean every(
jsweet.util.function.TriFunction<T, Integer, Array<T>, java.lang.Boolean> callbackfn);
@ -595,12 +578,12 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
*
* @param callbackfn
* A function that accepts up to three arguments. The some method
* calls the callbackfn function for each element in array1 until
* the callbackfn returns true, or until the end of the array.
* calls the callbackfn function for each element in array1 until the
* callbackfn returns true, or until the end of the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public java.lang.Boolean some(
jsweet.util.function.TriFunction<T, Integer, Array<T>, java.lang.Boolean> callbackfn);
@ -609,43 +592,42 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* Performs the specified action for each element in an array.
*
* @param callbackfn
* A function that accepts up to three arguments. forEach calls
* the callbackfn function one time for each element in the
* array.
* A function that accepts up to three arguments. forEach calls the
* callbackfn function one time for each element in the array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public void forEach(jsweet.util.function.TriConsumer<T, Integer, Array<T>> callbackfn);
/**
* Calls a defined callback function on each element of an array, and
* returns an array that contains the results.
* Calls a defined callback function on each element of an array, and returns an
* array that contains the results.
*
* @param callbackfn
* A function that accepts up to three arguments. The map method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public <U> Array<U> map(jsweet.util.function.TriFunction<T, Integer, Array<T>, U> callbackfn);
/**
* Calls a defined callback function on each element of an array, and
* returns an array that contains the results.
* Calls a defined callback function on each element of an array, and returns an
* array that contains the results.
*
* @param callbackfn
* A function that accepts up to three arguments. The map method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public <U> Array<U> map(java.util.function.Function<T, U> callbackfn);
@ -654,13 +636,13 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* callback function.
*
* @param callbackfn
* A function that accepts up to three arguments. The filter
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to three arguments. The filter method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public Array<T> filter(jsweet.util.function.TriFunction<T, Integer, Array<T>, java.lang.Boolean> callbackfn);
@ -669,48 +651,46 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
* callback function.
*
* @param callbackfn
* A function that accepts up to three arguments. The filter
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to three arguments. The filter method
* calls the callbackfn function one time for each element in the
* array.
* @param thisArg
* An object to which the this keyword can refer in the
* callbackfn function. If thisArg is omitted, undefined is used
* as the this value.
* An object to which the this keyword can refer in the callbackfn
* function. If thisArg is omitted, undefined is used as the this
* value.
*/
native public Array<T> filter(java.util.function.Function<T, java.lang.Boolean> callbackfn);
/**
* Calls the specified callback function for all the elements in an array.
* The return value of the callback function is the accumulated result, and
* is provided as an argument in the next call to the callback function.
* Calls the specified callback function for all the elements in an array. The
* return value of the callback function is the accumulated result, and is
* provided as an argument in the next call to the callback function.
*
* @param callbackfn
* A function that accepts up to four arguments. The reduce
* method calls the callbackfn function one time for each element
* in the array.
* A function that accepts up to four arguments. The reduce method
* calls the callbackfn function one time for each element in the
* array.
* @param initialValue
* If initialValue is specified, it is used as the initial value
* to start the accumulation. The first call to the callbackfn
* function provides this value as an argument instead of an
* array value.
* If initialValue is specified, it is used as the initial value to
* start the accumulation. The first call to the callbackfn function
* provides this value as an argument instead of an array value.
*/
native public T reduce(Function4<T, T, Integer, Array<T>, T> callbackfn);
/**
* Calls the specified callback function for all the elements in an array,
* in descending order. The return value of the callback function is the
* accumulated result, and is provided as an argument in the next call to
* the callback function.
* Calls the specified callback function for all the elements in an array, in
* descending order. The return value of the callback function is the
* accumulated result, and is provided as an argument in the next call to the
* callback function.
*
* @param callbackfn
* A function that accepts up to four arguments. The reduceRight
* method calls the callbackfn function one time for each element
* in the array.
* method calls the callbackfn function one time for each element in
* the array.
* @param initialValue
* If initialValue is specified, it is used as the initial value
* to start the accumulation. The first call to the callbackfn
* function provides this value as an argument instead of an
* array value.
* If initialValue is specified, it is used as the initial value to
* start the accumulation. The first call to the callbackfn function
* provides this value as an argument instead of an array value.
*/
native public T reduceRight(Function4<T, T, Integer, Array<T>, T> callbackfn);
@ -720,47 +700,44 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public static Array<Object> $applyStatic();
/**
* Returns the value of the first element in the array where predicate is
* true, and undefined otherwise.
* Returns the value of the first element in the array where predicate is true,
* and undefined otherwise.
*
* @param predicate
* find calls predicate once for each element of the array, in
* ascending order, until it finds one where predicate returns
* true. If such an element is found, find immediately returns
* that element value. Otherwise, find returns undefined.
* ascending order, until it finds one where predicate returns true.
* If such an element is found, find immediately returns that element
* value. Otherwise, find returns undefined.
* @param thisArg
* If provided, it will be used as the this value for each
* invocation of predicate. If it is not provided, undefined is
* used instead.
* If provided, it will be used as the this value for each invocation
* of predicate. If it is not provided, undefined is used instead.
*/
native public T find(jsweet.util.function.TriFunction<T, Integer, Array<T>, java.lang.Boolean> predicate);
/**
* Returns the index of the first element in the array where predicate is
* true, and undefined otherwise.
* Returns the index of the first element in the array where predicate is true,
* and undefined otherwise.
*
* @param predicate
* find calls predicate once for each element of the array, in
* ascending order, until it finds one where predicate returns
* true. If such an element is found, find immediately returns
* that element value. Otherwise, find returns undefined.
* ascending order, until it finds one where predicate returns true.
* If such an element is found, find immediately returns that element
* value. Otherwise, find returns undefined.
* @param thisArg
* If provided, it will be used as the this value for each
* invocation of predicate. If it is not provided, undefined is
* used instead.
* If provided, it will be used as the this value for each invocation
* of predicate. If it is not provided, undefined is used instead.
*/
native public int findIndex(java.util.function.Function<T, java.lang.Boolean> predicate);
/**
* Returns the this object after filling the section identified by start and
* end with value
* Returns the this object after filling the section identified by start and end
* with value
*
* @param value
* value to fill array section with
* @param start
* index to start filling the array at. If start is negative, it
* is treated as length+start where length is the length of the
* array.
* index to start filling the array at. If start is negative, it is
* treated as length+start where length is the length of the array.
* @param end
* index to stop filling the array at. If end is negative, it is
* treated as length+end.
@ -768,15 +745,14 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public Array<T> fill(T value, int start);
/**
* Returns the this object after filling the section identified by start and
* end with value
* Returns the this object after filling the section identified by start and end
* with value
*
* @param value
* value to fill array section with
* @param start
* index to start filling the array at. If start is negative, it
* is treated as length+start where length is the length of the
* array.
* index to start filling the array at. If start is negative, it is
* treated as length+start where length is the length of the array.
* @param end
* index to stop filling the array at. If end is negative, it is
* treated as length+end.
@ -784,18 +760,18 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
native public Array<T> fill(T value);
/**
* Returns the this object after copying a section of the array identified
* by start and end to the same array starting at position target
* Returns the this object after copying a section of the array identified by
* start and end to the same array starting at position target
*
* @param target
* If target is negative, it is treated as length+target where
* length is the length of the array.
* If target is negative, it is treated as length+target where length
* is the length of the array.
* @param start
* If start is negative, it is treated as length+start. If end is
* negative, it is treated as length+end.
* @param end
* If not specified, length of the this object is used as its
* default value.
* If not specified, length of the this object is used as its default
* value.
*/
native public Array<T> copyWithin(int target, int start);
@ -842,4 +818,6 @@ public class Array<T> extends Iterable<T> implements java.lang.Iterable<T> {
public InitialValueT(T initialValue) {
}
}
public static native <T> Array<T> from(java.lang.Object arrayLike);
}

View File

@ -5,6 +5,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import jsweet.lang.Name;
import jsweet.util.Lang;
/**
@ -77,7 +78,18 @@ public class Promise<T> extends PromiseLike<T> {
* An array of Promises.
* @returns A new Promise.
*/
native public static <T> Promise<T[]> all(IterableT<T> values);
@Name("all")
native public static <T> Promise<T[]> allFromValues(Iterable<T> values);
/**
* Creates a Promise that is resolved with an array of results when all of the
* provided Promises resolve, or rejected when any Promise is rejected.
*
* @param values
* An array of Promises.
* @returns A new Promise.
*/
native public static <T> Promise<T[]> all(Iterable<PromiseLike<T>> values);
/**
* Creates a Promise that is resolved or rejected when any of the provided
@ -212,16 +224,6 @@ public class Promise<T> extends PromiseLike<T> {
public Promise(BiConsumer<java.util.function.Consumer<T>, java.util.function.Consumer<java.lang.Object>> executor) {
}
/**
* Creates a Promise that is resolved with an array of results when all of the
* provided Promises resolve, or rejected when any Promise is rejected.
*
* @param values
* An array of Promises.
* @returns A new Promise.
*/
native public static <T> Promise<T[]> all(IterablePromiseLikeT<T> values);
/**
* Creates a Promise that is resolved or rejected when any of the provided
* Promises are resolved or rejected.