Эх сурвалжийг харах

Rename functions starting with "try" that return attempts to start with "attempt" instead

Billy Barrow 1 сар өмнө
parent
commit
dbee080895

+ 7 - 9
src/lib/Enumerable.vala

@@ -103,12 +103,12 @@ namespace Invercargill {
             return new TransformQuery<T, Tout>(this, (owned)transform);
         }
 
-        public virtual Attempts<Tout> try_select<Tout>(owned AttemptTransformDelegate<T, Tout> transform) {
+        public virtual Attempts<Tout> attempt_select<Tout>(owned AttemptTransformDelegate<T, Tout> transform) {
             return select<Attempt<Tout>>(i => new Attempt<Tout>(() => transform(i))).assert_promotion<Attempts>();
         }
 
-        public virtual Attempts<Tout> try_select_nested<Tout>(owned AttemptTransformDelegate<T, Enumerable<Attempt<Tout>>> transform) {
-            return try_select<Enumerable<Attempt<Tout>>>((owned)transform)
+        public virtual Attempts<Tout> attempt_select_nested<Tout>(owned AttemptTransformDelegate<T, Enumerable<Attempt<Tout>>> transform) {
+            return attempt_select<Enumerable<Attempt<Tout>>>((owned)transform)
                 .as_enumerable()
                 .select_many<Attempt<Tout>>(a => a.success ? a.result : Invercargill.single<Attempt<Tout>>(new Attempt<Tout>.unsuccessful(a.error)))
                 .assert_promotion<Attempts>();
@@ -264,10 +264,8 @@ namespace Invercargill {
             return keys.select<Grouping<TKey, T>>(g => new Grouping<TKey, T>(g, this.where(i => key_equality(g, key_selector(i)))));
         }
 
-        public virtual Enumerable<T> @with(T item) {
-            var seq = new Series<T>();
-            seq.add(item);
-            return concat(seq);
+        public virtual Enumerable<T> @with(T item, uint times = 1) {
+            return concat(range(0, (int)times, 1).select<T>(i => item));
         }
 
         public virtual T first(owned PredicateDelegate<T>? predicate = null) throws SequenceError {
@@ -450,8 +448,8 @@ namespace Invercargill {
             return series;
         }
 
-        public virtual Attempts<Tout> try_map_with<Tout>(Mapper<Tout, T> mapper) {
-            return try_select<Tout>(o => mapper.materialise(o));
+        public virtual Attempts<Tout> attempt_map_with<Tout>(Mapper<Tout, T> mapper) {
+            return attempt_select<Tout>(o => mapper.materialise(o));
         }
 
         public virtual Enumerable<T> as_enumerable() {

+ 8 - 8
src/lib/EnumerableProxy.vala

@@ -129,8 +129,8 @@ namespace Invercargill {
             return inner.matches(other, equals);
         }
     
-        public override Enumerable<T> with(T item) {
-            return inner.with(item);
+        public override Enumerable<T> with(T item, uint times = 1) {
+            return inner.with(item, times);
         }
     
         public override T first(owned PredicateDelegate<T>? predicate = null) throws SequenceError {
@@ -213,20 +213,20 @@ namespace Invercargill {
             return inner.select_where<Tout>((owned)transform);
         }
 
-        public override Attempts<Tout> try_select<Tout>(owned AttemptTransformDelegate<T, Tout> transform) {
-            return inner.try_select<Tout>((owned)transform);
+        public override Attempts<Tout> attempt_select<Tout>(owned AttemptTransformDelegate<T, Tout> transform) {
+            return inner.attempt_select<Tout>((owned)transform);
         }
 
-        public override Attempts<Tout> try_select_nested<Tout>(owned AttemptTransformDelegate<T, Enumerable<Attempt<Tout>>> transform) {
-            return inner.try_select_nested<Tout>((owned)transform);
+        public override Attempts<Tout> attempt_select_nested<Tout>(owned AttemptTransformDelegate<T, Enumerable<Attempt<Tout>>> transform) {
+            return inner.attempt_select_nested<Tout>((owned)transform);
         }   
 
         public override Enumerable<T> cache() {
             return inner.cache();
         }
 
-        public override Attempts<Tout> try_map_with<Tout>(Mapper<Tout, T> mapper) {
-            return inner.try_map_with<Tout>(mapper);
+        public override Attempts<Tout> attempt_map_with<Tout>(Mapper<Tout, T> mapper) {
+            return inner.attempt_map_with<Tout>(mapper);
         }
         
         public override Enumerable<T> as_enumerable() {

+ 6 - 6
src/lib/Promotions/AttemptEnumerable.vala

@@ -228,19 +228,19 @@ namespace Invercargill {
             return inner.select_where<Tout>((a, ref o) => !a.success || transform(a.result, ref o)).assert_promotion<Attempts<Tout>>();
         }
 
-        public new Attempts<Tout> try_select<Tout>(owned AttemptTransformDelegate<T, Tout> transform) {
-            return inner.try_select<Tout>(a => a.success ? new Attempt<Tout>(() => transform(a.result)) : new Attempt<Tout>.unsuccessful(a.error));
+        public new Attempts<Tout> attempt_select<Tout>(owned AttemptTransformDelegate<T, Tout> transform) {
+            return inner.attempt_select<Tout>(a => a.success ? new Attempt<Tout>(() => transform(a.result)) : new Attempt<Tout>.unsuccessful(a.error));
         }
 
-        public new Attempts<Tout> try_select_nested<Tout>(owned AttemptTransformDelegate<T, Enumerable<Attempt<Tout>>> transform) {
-            return try_select<Enumerable<Attempt<Tout>>>((owned)transform)
+        public new Attempts<Tout> attempt_select_nested<Tout>(owned AttemptTransformDelegate<T, Enumerable<Attempt<Tout>>> transform) {
+            return attempt_select<Enumerable<Attempt<Tout>>>((owned)transform)
                 .as_enumerable()
                 .select_many<Attempt<Tout>>(a => a.success ? a.result : Invercargill.single<Attempt<Tout>>(new Attempt<Tout>.unsuccessful(a.error)))
                 .assert_promotion<Attempts<Tout>>();
         }
 
-        public new Attempts<Tout> try_map_with<Tout>(Mapper<Tout, T> mapper) {
-            return try_select<Tout>(o => mapper.materialise(o));
+        public new Attempts<Tout> attempt_map_with<Tout>(Mapper<Tout, T> mapper) {
+            return attempt_select<Tout>(o => mapper.materialise(o));
         }
 
 

+ 2 - 2
src/lib/Promotions/PropertyGroupEnumerable.vala

@@ -11,8 +11,8 @@ namespace Invercargill {
             return element_type.is_a (typeof(Properties));
         }
 
-        public new Attempts<Tout> try_map_with<Tout>(PropertyMapper<Tout> mapper) {
-            return inner.try_map_with<Tout>(mapper);
+        public new Attempts<Tout> attempt_map_with<Tout>(PropertyMapper<Tout> mapper) {
+            return inner.attempt_map_with<Tout>(mapper);
         }
 
     }

+ 1 - 1
src/lib/PropertyMapper.vala

@@ -148,7 +148,7 @@ namespace Invercargill {
         public virtual PropertyMappingBuilder<T> map_many_with<TNative, TElement>(string name, owned PropertyGetter<T, Enumerable<TNative>> getter, owned PropertySetter<T, Enumerable<TNative>> setter, Mapper<TNative, TElement> mapper) {
             var mapping = new PropertyMapping<T>() {
                 name = name,
-                getter = (o) => new NativeElement<Elements>(getter(o).try_select<TElement>(i => mapper.map_from(i)).to_elements()),
+                getter = (o) => new NativeElement<Elements>(getter(o).attempt_select<TElement>(i => mapper.map_from(i)).to_elements()),
                 setter = (o,d) => {
                     var collection = new Series<TNative>();
                     foreach (var properties in d.as<Elements>().elements_as<TElement>()) {

+ 2 - 2
src/lib/StickyPromotion.vala

@@ -25,8 +25,8 @@ namespace Invercargill {
             return (TPromotion)wrap(inner.skip(count));
         }
     
-        public new TPromotion with(T item) {
-            return (TPromotion)wrap(inner.with(item));
+        public new TPromotion with(T item, uint times = 1) {
+            return (TPromotion)wrap(inner.with(item, times));
         }
     
         public new TPromotion seal() {