|
@@ -19,6 +19,97 @@ namespace Invercargill {
|
|
return all(a => a.success);
|
|
return all(a => a.success);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public bool unwrap_iterate_if(PredicateDelegate<T> handler) throws Error {
|
|
|
|
+ var tracker = get_tracker();
|
|
|
|
+ while(tracker.has_next()) {
|
|
|
|
+ var item = tracker.get_next();
|
|
|
|
+ if(item.success) {
|
|
|
|
+ if(!handler(item.result)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ throw item.error;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void unwrap_iterate(ItemDelegate<T> handler) throws Error {
|
|
|
|
+ unwrap_iterate_if(i => {
|
|
|
|
+ handler(i);
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Series<T> unwrap_to_series() throws Error {
|
|
|
|
+ var series = new Series<T>();
|
|
|
|
+ unwrap_iterate(i => series.add(i));
|
|
|
|
+ return series;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Gee.Collection<T> unwrap_to_gee_collection() throws Error {
|
|
|
|
+ var collection = new Gee.LinkedList<T>();
|
|
|
|
+ unwrap_iterate(i => collection.add(i));
|
|
|
|
+ return collection;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual T[] unwrap_to_array() throws Error {
|
|
|
|
+ var array = new T[1024];
|
|
|
|
+ var index = 0;
|
|
|
|
+ foreach (var item in this) {
|
|
|
|
+ if(!item.success) {
|
|
|
|
+ throw item.error;
|
|
|
|
+ }
|
|
|
|
+ if(index >= array.length) {
|
|
|
|
+ array.resize(array.length*2);
|
|
|
|
+ }
|
|
|
|
+ safely_assign_to_array<T>(array, index, item.result);
|
|
|
|
+ index++;
|
|
|
|
+ }
|
|
|
|
+ array.resize(index);
|
|
|
|
+ return array;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Vector<T> unwrap_to_vector() throws Error {
|
|
|
|
+ var vector = new Vector<T>();
|
|
|
|
+ unwrap_iterate(i => vector.add(i));
|
|
|
|
+ return vector;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Dictionary<TKey, T> unwrap_to_dictionary<TKey>(TransformDelegate<T, TKey> key_selecter, HashFunc<TKey>? key_hash_func = null, EqualFunc<TKey>? key_equal_func = null) throws Error {
|
|
|
|
+ var dict = new Dictionary<TKey, T>(key_hash_func, key_equal_func);
|
|
|
|
+ unwrap_iterate(i => dict.set(key_selecter(i), i));
|
|
|
|
+ return dict;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Dictionary<TKey, TValue> unwrap_select_to_dictionary<TKey, TValue>(TransformDelegate<T, TKey> key_selecter, TransformDelegate<T, TValue> value_selecter, HashFunc<TKey>? key_hash_func = null, EqualFunc<TKey>? key_equal_func = null) throws Error {
|
|
|
|
+ var dict = new Dictionary<TKey, T>(key_hash_func, key_equal_func);
|
|
|
|
+ unwrap_iterate(i => dict.set(key_selecter(i), value_selecter(i)));
|
|
|
|
+ return dict;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Set<T> unwrap_to_set(HashFunc<T>? hash_func = null, EqualFunc<T>? equal_func = null) throws Error {
|
|
|
|
+ var @set = new Set<T>(hash_func, equal_func);
|
|
|
|
+ unwrap_iterate(i => @set.add(i));
|
|
|
|
+ return @set;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Elements unwrap_to_elements() throws Error {
|
|
|
|
+ var series = new ElementSeries();
|
|
|
|
+ if(typeof(T).is_a(typeof(Element))) {
|
|
|
|
+ unwrap_iterate(i => series.add((Element)i));
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ unwrap_iterate(i => series.add(new NativeElement<T>(i)));
|
|
|
|
+ }
|
|
|
|
+ return series;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Object[] unwrap_to_object_array() throws Error {
|
|
|
|
+ return unwrap_to_vector().to_object_array();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|