Function
func all<T>((T) -> Bool)
public func all<T>(predicate: (T) -> Bool): (Iterable<T>) -> Bool
Description: Checks whether all elements of the iterator meet a specified condition.
Parameters:
- predicate: (T) -> Bool: specified condition
Returns:
func any<T>((T) -> Bool)
public func any<T>(predicate: (T) -> Bool): (Iterable<T>) -> Bool
Description: Checks whether an element that meets a specified condition exists in the iterator.
Parameters:
- predicate: (T) -> Bool: specified condition
Returns:
func at<T>(Int64)
public func at<T>(n: Int64): (Iterable<T>) -> Option<T>
Description: Obtains the element at the specified location of an iterator.
Parameters:
- n: Int64: specified location
Returns:
- (Iterable<T>) -> Option<T>: function that obtains the element at the specified location. If the iterator is empty, the function returns None.
func collectArrayList<T>(Iterable<T>)
public func collectArrayList<T>(it: Iterable<T>): ArrayList<T>
Description: Converts an iterator to an ArrayList instance.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
func collectArray<T>(Iterable<T>)
public func collectArray<T>(it: Iterable<T>): Array<T>
Description: Converts an iterator to an Array instance.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Array<T>: array
func collectHashMap<K, V>(Iterable<(K, V)>) where K <: Hashable & Equatable<K>
public func collectHashMap<K, V>(it: Iterable<(K, V)>): HashMap<K, V> where K <: Hashable & Equatable<K>
Description: Converts an iterator to a HashMap instance.
Parameters:
- it: Iterable<(K, V)>: specified iterator
Returns:
func collectHashSet<T>(Iterable<T>) where T <: Hashable & Equatable<T>
public func collectHashSet<T>(it: Iterable<T>): HashSet<T> where T <: Hashable & Equatable<T>
Description: Converts an iterator to a HashSet instance.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
func collectString<T>(String) where T <: ToString
public func collectString<T>(delimiter!: String = ""): (Iterable<T>) -> String where T <: ToString
Description: Converts an iterator whose elements implement the ToString interface to a String instance.
Parameters:
- delimiter!: String: string concatenation delimiter
Returns:
func concat<T>(Iterable<T>)
public func concat<T>(other: Iterable<T>): (Iterable<T>) -> Iterator<T>
Description: Concatenates two iterators in series.
Parameters:
- other: Iterable<T>: iterator to be concatenated behind
Returns:
func contains<T>(T) where T <: Equatable<T>
public func contains<T>(element: T): (Iterable<T>) -> Bool where T <: Equatable<T>
Description: Traverses all elements, checks whether a specified element is included, and returns the element.
Parameters:
- element: T: element to be searched for
Returns:
func count<T>(Iterable<T>)
public func count<T>(it: Iterable<T>): Int64
Description: Counts the number of elements contained in an iterator.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Int64: number of elements contained in the iterator
func enumerate<T>(Iterable<T>)
public func enumerate<T>(it: Iterable<T>): Iterator<(Int64, T)>
Description: Obtains an iterator with indexes.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
func filter<T>((T) -> Bool)
public func filter<T>(predicate: (T) -> Bool): (Iterable<T>) -> Iterator<T>
Description: Filters out elements that meet a specified condition.
Parameters:
- predicate: (T) -> Bool: specified condition
Returns:
func filterMap<T, R>((T) -> ?R)
public func filterMap<T, R>(transform: (T)-> ?R): (Iterable<T>) ->Iterator<R>
Description: Performs filter and map operations at the same time and returns a new iterator.
Parameters:
- transform: (T) -> ?R: specified mapping function If the return value of this function is Some, predicate of the filter is true; otherwise, predicate of the filter is false.
Returns:
func first<T>(Iterable<T>)
public func first<T>(it: Iterable<T>): Option<T>
Description: Obtains the first element.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Option<T>: The element (if there is) is returned. Otherwise, None is returned.
func flatMap<T, R>( (T) -> Iterable<R>)
public func flatMap<T, R>(transform: (T) -> Iterable<R>): (Iterable<T>) -> Iterator<R>
Description: Creates a mapping with the flatten function.
Parameters:
- transform: (T) -> Iterable<R>: specified mapping function
Returns:
func flatten<T, R>(Iterable<T>) where T <: Iterable<R>
public func flatten<T, R>(it: Iterable<T>): Iterator<R> where T <: Iterable<R>
Description: Unfolds one layer of a nested iterator.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Iterator<R>: iterator after one layer is expanded
func fold<T, R>(R, (R, T) -> R)
public func fold<T, R>(initial: R, operation: (R, T) -> R): (Iterable<T>) -> R
Description: Uses a specified initial value to calculate from left to right.
Parameters:
- initial: R: specified initial value of the R type
- operation: (R, T) -> R: specified calculation function
Returns:
- (Iterable<T>) -> R: folding function
func forEach<T>((T) -> Unit)
public func forEach<T>(action: (T) -> Unit): (Iterable<T>) -> Unit
Description: Traverses all elements in an iterator to complete a specified operation.
Parameters:
- action: (T) -> Unit: specified operation function
Returns:
func inspect<T>((T) -> Unit)
public func inspect<T>(action: (T)->Unit): (Iterable<T>) ->Iterator<T>
Description: Performs an extra operation on the current element each time the iterator calls next() (without consuming elements in the iterator).
Parameters:
- action: (T) -> Unit: specified operation function
Returns:
- (Iterable<T>) -> Iterator<T>: function that can perform an extra operation on each element of the iterator
func isEmpty<T>(Iterable<T>)
public func isEmpty<T>(it: Iterable<T>): Bool
Description: Checks whether an iterator is empty.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Bool: result of whether the iterator is empty
func last<T>(Iterable<T>)
public func last<T>(it: Iterable<T>): Option<T>
Description: Obtains the last element.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Option<T>: The element (if there is) is returned. Otherwise, None is returned.
func map<T, R>((T) -> R)
public func map<T, R>(transform: (T) -> R): (Iterable<T>) -> Iterator<R>
Description: Create a mapping.
Parameters:
- transform: (T) ->R: specified mapping function
Returns:
func max<T>(Iterable<T>) where T <: Comparable<T>
public func max<T>(it: Iterable<T>): Option<T> where T <: Comparable<T>
Description: Filters out the element of the maximum value.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Option<T>: The element (if there is) is returned. Otherwise, None is returned.
func min<T>(Iterable<T>) where T <: Comparable<T>
public func min<T>(it: Iterable<T>): Option<T> where T <: Comparable<T>
Description: Filters out the element of the minimum value.
Parameters:
- it: Iterable<T>: specified iterator
Returns:
- Option<T>: The element (if there is) is returned. Otherwise, None is returned.
func none<T>((T) -> Bool)
public func none<T>(predicate: (T) -> Bool): (Iterable<T>) -> Bool
Description: Checks whether no element of the iterator meets a specified condition.
Parameters:
- predicate: (T) -> Bool: specified condition
Returns:
func reduce<T>((T, T) -> T)
public func reduce<T>(operation: (T, T) -> T): (Iterable<T>) -> Option<T>
Description: Uses the first element as the initial value to calculate from left to right.
Parameters:
- operation: (T, T) -> T: specified operation function
Returns:
func skip<T>(Int64)
public func skip<T>(count: Int64): (Iterable<T>) -> Iterator<T>
Description: Skips a specific number of elements in an iterator.
If the value of count is less than 0, an exception is thrown. If the value of count is 0, no element is skipped and the original iterator is returned. If the value of count is greater than 0 and less than the size of the iterator, count elements are skipped and a new iterator containing the remaining elements is returned. If the value of count is greater than or equal to the size of the iterator, all elements are skipped and an empty iterator is returned.
Parameters:
- count: Int64: number of elements to be skipped
Returns:
Throws:
- IllegalArgumentException: If the value of count is less than 0, this exception is thrown.
func step<T>(Int64)
public func step<T>(count: Int64): (Iterable<T>) -> Iterator<T>
Description: Each time next() is called, a specified number of elements in the iterator are skipped.
If the value of count is less than or equal to 0, an exception is thrown. If the value of count is greater than 0, next() is called to skip count elements until the iterator becomes empty.
Parameters:
- count: Int64: number of elements to be skipped each time next() is called
Returns:
- (Iterable<T>) -> Iterator<T>: function after a specific number of elements are skipped each time the iterator calls next()
Throws:
- IllegalArgumentException: If the value of count is less than or equal to 0, this exception is thrown.
func take<T>(Int64)
public func take<T>(count: Int64): (Iterable<T>) -> Iterator<T>
Description: Takes a specified number of elements from an iterator.
If the value of count is less than 0, an exception is thrown. If the value of count is 0, no element is taken and an empty iterator is returned. If the value of count is greater than 0 and less than the size of the iterator, the first count elements are taken and a new iterator is returned. If the value of count is greater than or equal to the size of the iterator, all elements are taken and the original iterator is returned.
Parameters:
- count: Int64: number of elements to be taken
Returns:
Throws:
- IllegalArgumentException: If the value of count is less than 0, this exception is thrown.
func zip<T, R>(Iterable<R>)
public func zip<T, R>(other: Iterable<R>): (Iterable<T>) -> Iterator<(T, R)>
Description: Combines two iterators into one (the length depends on the shorter iterator).
Parameters:
- other: Iterable<R>: one iterator for the combination
Returns: