Przeglądaj źródła

Enumerable inherits from GLib.Object now,
Added Invercargill.single helper funtion,
Add cast and to_object_array Enumerable functions

Billy Barrow 2 lat temu
rodzic
commit
51bc375daf

+ 12 - 1
src/lib/Enumerable.vala

@@ -1,7 +1,7 @@
 
 namespace Invercargill {
 
-    public abstract class Enumerable<T> {
+    public abstract class Enumerable<T> : Object {
 
         public abstract Tracker<T> get_tracker();
 
@@ -99,6 +99,10 @@ namespace Invercargill {
             return new SkipQuery<T>(this, count);
         }
 
+        public virtual Enumerable<Tout> cast<Tout>() {
+            return select<Tout>(i => (Tout)i);
+        }
+
         public virtual Enumerable<Tout> parallel_select<Tout>(owned TransformDelegate<T, Tout> transform, uint workers = 0) {
             var actual_workers = workers;
             if(actual_workers < 1) {
@@ -205,6 +209,13 @@ namespace Invercargill {
             });
         }
 
+        public virtual Object[] to_object_array() throws SequenceError {
+            if(!typeof(T).is_object()) {
+                throw new SequenceError.INVALID_TYPE("Can only make an object array of an Enumerable<T> where T is derrived from GLib.Object");
+            }
+            return select<Object>(i => (Object)i).to_array();
+        }
+
     }
 
 }

+ 6 - 1
src/lib/Invercargill.vala

@@ -32,6 +32,12 @@ namespace Invercargill {
         return new EmptyEnumerable<T>();
     }
 
+    public static Enumerable<T> single<T>(T item) {
+        var seq = new Invercargill.Sequence<T>();
+        seq.add(item);
+        return seq;
+    }
+
     public static TransformDelegate<Tin, Tout> trycatch<Tin, Tout>(ErrorThrowingDelegate<Tin, Tout> main, ErrorCatchingDelegate<Tin, Tout> handler) {
         return (i) => {
             try {
@@ -54,5 +60,4 @@ namespace Invercargill {
         };
     }
 
-
 }

+ 2 - 1
src/lib/SequenceError.vala

@@ -1,6 +1,7 @@
 namespace Invercargill {
     public errordomain SequenceError {
         NO_ELEMENTS,
-        MULTUPLE_ELEMENTS
+        MULTUPLE_ELEMENTS,
+        INVALID_TYPE
     }
 }

+ 1 - 1
src/lib/meson.build

@@ -49,7 +49,7 @@ pkg.generate(invercargill,
     name : 'invercargill',)
     
 g_ir_compiler = find_program('g-ir-compiler')
-custom_target('invercargill typelib', command: [g_ir_compiler, '--shared-library=invercargill.so', '--output', '@OUTPUT@', meson.current_build_dir() / 'invercargill-1.0.gir'],
+custom_target('invercargill typelib', command: [g_ir_compiler, '--shared-library=libinvercargill.so', '--output', '@OUTPUT@', meson.current_build_dir() / 'invercargill-1.0.gir'],
               output: 'invercargill-1.0.typelib',
               depends: invercargill,
               install: true,