Sfoglia il codice sorgente

fix(attempts): pass result to predicate in where method

The where method was incorrectly passing the entire Attempt object to
the predicate instead of just the result value. This fix ensures the
predicate receives the unwrapped result as expected.

Also adds to_immutable_buffer() and to_buffer() conversion methods,
and temporary debug print statements for troubleshooting.
Billy Barrow 3 settimane fa
parent
commit
cf049729e9

+ 1 - 0
src/lib/DataStructures/ByteBuffer.vala

@@ -12,6 +12,7 @@ namespace Invercargill.DataStructures {
         }
 
         protected BinaryData adhere(Enumerable<uint8> enumerable) {
+            print("Adhere\n");
             return enumerable.assert_promotion<BinaryData>();
         }
 

+ 10 - 1
src/lib/Promotions/Attempts.vala

@@ -76,12 +76,21 @@ namespace Invercargill {
             return array;
         }
 
+        public new ImmutableBuffer<T> to_immutable_buffer() throws Error {
+            return to_series().to_immutable_buffer();
+        }
+
         public new Vector<T> to_vector() throws Error {
             var vector = new Vector<T>();
             iterate(i => vector.add(i));
             return vector;
         }
 
+        public new Buffer<T> to_buffer() throws Error {
+            var array = to_array();
+            return new Buffer<T>.take_array(array);
+        }
+
         public new Dictionary<TKey, T> to_dictionary<TKey>(TransformDelegate<T, TKey> key_selecter, HashDelegate<TKey>? key_hash_func = null, EqualityDelegate<TKey>? key_equal_func = null) throws Error {
             var dict = new Dictionary<TKey, T>(key_hash_func, key_equal_func);       
             iterate(i => dict.set(key_selecter(i), i));
@@ -141,7 +150,7 @@ namespace Invercargill {
         }
 
         public new Attempts<T> where(owned PredicateDelegate<T> predicate) {
-            return inner.where(i => !i.success || predicate(i)).assert_promotion<Attempts<T>>();
+            return inner.where(i => !i.success || predicate(i.result)).assert_promotion<Attempts<T>>();
         }
     
         public new Attempts<TOut> select<TOut>(owned TransformDelegate<T, TOut> transform) {

+ 1 - 0
src/lib/Promotions/BinaryData.vala

@@ -26,6 +26,7 @@ namespace Invercargill {
         }
 
         public virtual ByteBuffer to_byte_buffer() {
+            print("hello?\n");
             return new ByteBuffer.from_enumerable(this);
         }