Lists
Object Hierarchy:
Description:
public class Lists : Object
Static utility methods for ArrayList operations.
Lists provides high-level operations like partition, chunk, zip, flatten, and groupBy that would otherwise require 5-15 lines of manual
loop code.
Example:
var list = new ArrayList<string> (GLib.str_equal);
list.add ("a");
list.add ("b");
list.add ("c");
list.add ("d");
var chunks = Lists.chunkString (list, 2);
// chunks: [["a","b"], ["c","d"]]
Content:
Static methods:
- public static ArrayList<ArrayList<T>> chunk<T> (ArrayList<T> list, int size)
Splits a list into fixed-size chunks.
- public static ArrayList<ArrayList<string>> chunkString (ArrayList<string> list, int size)
Splits a string list into sub-lists of the given size. The last chunk
may be smaller.
- public static ArrayList<T> distinct<T> (ArrayList<T> list, HashFunc<T> hash_func, EqualFunc<T> equal_func)
Removes duplicate elements while preserving order.
- public static ArrayList<string> distinctString (ArrayList<string> list)
Removes duplicates from a string list, preserving order.
- public static ArrayList<T> flatten<T> (ArrayList<ArrayList<T>> nested)
Flattens nested lists into one list.
- public static ArrayList<string> flattenString (ArrayList<ArrayList<string>> nested)
Flattens a nested list of string lists into a single list.
- public static HashMap<T,int> frequency<T> (ArrayList<T> list, HashFunc<T> hash_func, EqualFunc<T> equal_func)
Counts element frequencies in a list.
- public static HashMap<string,int> frequencyString (ArrayList<string> list)
Counts the frequency of each string in the list.
- public static HashMap<K,ArrayList<T>> groupBy<T,K> (ArrayList<T> list, owned MapFunc<T,K> keyFn, HashFunc<K> hash_func, EqualFunc<K> equal_func)
Groups list elements by computed keys.
- public static HashMap<string,ArrayList<string>> groupByString (ArrayList<string> list, owned MapFunc<string,string> keyFn)
Groups elements by a key extracted from each element.
- public static ArrayList<T> interleave<T> (ArrayList<T> a, ArrayList<T> b)
Interleaves two lists by alternating elements.
- public static ArrayList<string> interleaveString (ArrayList<string> a, ArrayList<string> b)
Interleaves two string lists by alternating elements.
- public static Pair<ArrayList<T>,ArrayList<T>> partition<T> (ArrayList<T> list, owned PredicateFunc<T> fn)
Splits a list into matching and non-matching lists.
- public static Pair<ArrayList<string>,ArrayList<string>> partitionString (ArrayList<string> list, owned PredicateFunc<string> fn)
Splits a string list into two lists based on a predicate. The first
list contains elements matching the predicate, the second contains the rest.
- public static ArrayList<string> reverseString (ArrayList<string> list)
Returns a reversed copy of the string list.
- public static ArrayList<T> rotate<T> (ArrayList<T> list, int distance)
Rotates elements by distance and returns new list. Positive values
rotate right, negative rotate left.
- public static ArrayList<T> shuffle<T> (ArrayList<T> list)
Returns a shuffled copy of the list.
- public static ArrayList<ArrayList<T>> sliding<T> (ArrayList<T> list, int windowSize)
Returns sliding windows over a list.
- public static ArrayList<ArrayList<string>> slidingString (ArrayList<string> list, int windowSize)
Returns sliding windows of the given size over the list.
- public static ArrayList<T> sortBy<T,K> (ArrayList<T> list, owned MapFunc<T,K> keyFn, owned ComparatorFunc<K> cmp)
Sorts list by computed key using key comparator.
- public static ArrayList<Pair<A,B>> zip<A,B> (ArrayList<A> a, ArrayList<B> b)
Combines two lists into list of pairs. Result size is minimum of both
input sizes.
- public static ArrayList<Pair<string,string>> zipString (ArrayList<string> a, ArrayList<string> b)
Combines two string lists into a list of Pairs. The result length is
the minimum of both list sizes.
- public static ArrayList<Pair<int,T>> zipWithIndex<T> (ArrayList<T> list)
Creates (index, element) pairs for a list.
- public static ArrayList<Pair<int,string>> zipWithIndexString (ArrayList<string> list)
Creates a list of Pairs with each element and its index.
Creation methods:
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref