Example #1
0
 public static object Complement(IApply func)
 {
     Func<object[], object> c = args =>
     {
         return !ToBool(Apply(func, args));
     };
     return new ApplyWrapper2(c);
 }
 public object GetValue()
 {
     if (Recipe != null)
     {
         Result = Runtime.Funcall(Recipe);
         Recipe = null;
     }
     return Result;
 }
Example #3
0
 public static object Funcall(IApply func, params object[] args)
 {
     if (func == null)
     {
         return Identity(args);
     }
     else
     {
         return func.Apply(args);
     }
 }
Example #4
0
 public static bool Any(IApply predicate, IEnumerable seq, IApply key)
 {
     foreach (var v in ToIter(seq))
     {
         if (FuncallBool(predicate, Funcall(key, v)))
         {
             return true;
         }
     }
     return false;
 }
Example #5
0
            public static Cons Assoc(object item, Cons seq, IApply test, IApply key)
            {
                int i = -1;

                foreach (Cons x in ToIter(seq))
                {
                    ++i;

                    if (FuncallBool(test, item, Funcall(key, Car(x))))
                    {
                        return x;
                    }
                }

                return null;
            }
Example #6
0
            public static Cons AssocIf(IApply predicate, Cons seq, IApply key)
            {
                int i = -1;

                foreach (Cons x in ToIter(seq))
                {
                    ++i;

                    if (FuncallBool(predicate, Funcall(key, Car(x))))
                    {
                        return x;
                    }
                }

                return null;
            }
Example #7
0
        public ApplyLawsTests(IApply <TF> apply, IEqK <TF> eqK) : base(apply, eqK)
        {
            var applyLaws = new ApplyLaws <TF>(apply);

            Add("Apply Composition", args =>
                applyLaws.ApplyComposition(args.LiftedA, args.LiftedFuncAtoB, args.LiftedFuncBtoC).Holds(eqK));

            Add("Map2 Product Consistency", args =>
                applyLaws
                .Map2ProductConsistency(args.LiftedA, args.LiftedB, (a, b) => a.GetHashCode() == b.GetHashCode())
                .Holds(eqK));

            Add("ProductL Consistency", args =>
                applyLaws.ProductLConsistency(args.LiftedA, args.LiftedB).Holds(eqK));

            Add("ProductR Consistency", args =>
                applyLaws.ProductRConsistency(args.LiftedA, args.LiftedB).Holds(eqK));
        }
Example #8
0
            public static IEnumerable Reductions(IApply reducer, IEnumerable seq, object seed, IApply key)
            {
                var result = seed;

                foreach (object x in ToIter(seq))
                {
                    if (result == MissingValue)
                    {
                        result = Funcall(key, x);
                    }
                    else
                    {
                        result = Funcall(reducer, result, Funcall(key, x));
                    }

                    yield return(result);
                }
            }
Example #9
0
        /// <summary>
        /// 删除该申请单所有相关的信息
        /// </summary>
        /// <param name="apply_id">申请单ID</param>
        /// <param name="trans">事务对象</param>
        public void DeleteApplyRelated(string apply_id, DbTransaction trans = null)
        {
            IApply dal = baseDal as IApply;

            dal.DeleteFormTableData(apply_id, trans);//必须先关联删除这个,然后删除表单数据
            dal.Delete(apply_id, trans);

            BLLFactory <ApplyFlow> .Instance.DeleteAllFlow(apply_id, trans);

            BLLFactory <ApplyUser> .Instance.DeleteByApplyId(apply_id, trans);

            string condition = string.Format("APPLY_ID='{0}' ", apply_id);

            BLLFactory <ApplyLog> .Instance.DeleteByCondition(condition, trans);

            BLLFactory <ApplyFlowlog> .Instance.DeleteByCondition(condition, trans);

            BLLFactory <ApplyRead> .Instance.DeleteByCondition(condition, trans);
        }
Example #10
0
 public static Cons Sequence(IApply xform, params IEnumerable[] seqs)
 {
     if (seqs == null || seqs.Length == 0)
     {
         return(null);
     }
     else if (seqs.Length == 1)
     {
         var seq      = seqs[0];
         var eduction = new Reducible(xform, seq, false);
         return(eduction.AsLazyList());
     }
     else
     {
         var seq      = new UnisonEnumerator(seqs);
         var eduction = new Reducible(xform, seq, true);
         return(eduction.AsLazyList());
     }
 }
Example #11
0
            public static IEnumerable DropWhile(IApply pred, IEnumerable seq)
            {
                if (seq == null)
                {
                    return(null);
                }

                var iter = seq.GetEnumerator();

                while (iter.MoveNext())
                {
                    if (!FuncallBool(pred, iter.Current))
                    {
                        return(MakeCons(iter.Current, iter));
                    }
                }

                return(null);
            }
Example #12
0
        public static IApply Completing(IApply f, IApply cf)
        {
            ApplyFunc nrf = args =>
            {
                switch (args.Length)
                {
                case 0:
                    return(Funcall(f));

                case 1:
                    return(Funcall(cf, args[0]));

                default:
                    return(Apply(f, args));
                }
            };

            return(new ApplyWrapper2(nrf));
        }
Example #13
0
            internal static IApply DropWhile(IApply f)
            {
                ApplyFunc xform = rfs =>
                {
                    var       rf      = (IApply)rfs[0];
                    var       dropped = false;
                    ApplyFunc nrf     = args =>
                    {
                        switch (args.Length)
                        {
                        case 0:
                            return(Funcall(rf));

                        case 1:
                            return(Funcall(rf, args[0]));

                        default:
                            var result = args[0];
                            var input  = args[1];
                            if (!dropped)
                            {
                                if (FuncallBool(f, input))
                                {
                                    return(result);
                                }
                                else
                                {
                                    dropped = true;
                                    return(Apply(rf, args));
                                }
                            }
                            else
                            {
                                return(Apply(rf, args));
                            }
                        }
                    };
                    return(new ApplyWrapper2(nrf));
                };

                return(new ApplyWrapper2(xform));
            }
Example #14
0
            public static IEnumerable ParallelMap(IApply action, IEnumerable seq)
            {
                if (seq == null)
                {
                    return(null);
                }
                var seq2     = ConvertToEnumerableObject(seq);
                var seq3     = seq2.AsParallel().AsOrdered();
                var specials = GetCurrentThread().SpecialStack;

                Func <object, object> wrapper = a =>
                {
                    // We want an empty threadcontext because threads may be reused
                    // and already have a broken threadcontext.
                    CurrentThreadContext = new ThreadContext(specials);
                    return(Funcall(action, a));
                };

                return(seq3.Select(wrapper));
            }
Example #15
0
            public static IEnumerable Merge(IEnumerable seq1, IEnumerable seq2, IApply test, IApply key)
            {
                IEnumerator iter1  = seq1.GetEnumerator();
                IEnumerator iter2  = seq2.GetEnumerator();
                bool        atEnd1 = !iter1.MoveNext();
                bool        atEnd2 = !iter2.MoveNext();

                while (!atEnd1 && !atEnd2)
                {
                    //
                    // put in the first element when it is less than or equal to the second element: stable merge
                    //

                    if (FuncallInt(test, Funcall(key, iter1.Current), Funcall(key, iter2.Current)) <= 0)
                    {
                        yield return(iter1.Current);

                        atEnd1 = !iter1.MoveNext();
                    }
                    else
                    {
                        yield return(iter2.Current);

                        atEnd2 = !iter2.MoveNext();
                    }
                }

                while (!atEnd1)
                {
                    yield return(iter1.Current);

                    atEnd1 = !iter1.MoveNext();
                }

                while (!atEnd2)
                {
                    yield return(iter2.Current);

                    atEnd2 = !iter2.MoveNext();
                }
            }
Example #16
0
            public static IEnumerable Iterate(int count, IApply func, object val)
            {
                if (count < 0)
                {
                    while (true)
                    {
                        yield return(val);

                        val = Funcall(func, val);
                    }
                }
                else
                {
                    while (count-- > 0)
                    {
                        yield return(val);

                        val = Funcall(func, val);
                    }
                }
            }
Example #17
0
            public static object Mismatch(IApply test, IEnumerable seq1, IEnumerable seq2)
            {
                IEnumerator iter1    = ToIter(seq1).GetEnumerator();
                IEnumerator iter2    = ToIter(seq2).GetEnumerator();
                bool        atEnd1   = !iter1.MoveNext();
                bool        atEnd2   = !iter2.MoveNext();
                int         position = 0;

                while (!atEnd1 && !atEnd2)
                {
                    if (test == null)
                    {
                        if (!Equal(iter1.Current, iter2.Current))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!FuncallBool(test, iter1.Current, iter2.Current))
                        {
                            break;
                        }
                    }

                    atEnd1 = !iter1.MoveNext();
                    atEnd2 = !iter2.MoveNext();
                    ++position;
                }

                if (atEnd1 && atEnd2)
                {
                    return(null);
                }
                else
                {
                    return(position);
                }
            }
Example #18
0
            public static IEnumerable PartitionBy(IApply func, int maxParts, IEnumerable seq)
            {
                object previous = null;
                var    all      = new Vector();
                Vector v        = null;

                foreach (var item in ToIter(seq))
                {
                    if (v == null)
                    {
                        v = new Vector();
                        v.Add(item);
                        previous = Funcall(func, item);
                    }
                    else
                    {
                        var current = Funcall(func, item);
                        if (all.Count + 1 == maxParts || Equal(current, previous))
                        {
                            v.Add(item);
                        }
                        else
                        {
                            all.Add(AsList(v));
                            v        = new Vector();
                            previous = current;
                            v.Add(item);
                        }
                    }
                }

                if (v != null)
                {
                    all.Add(AsList(v));
                }
                return(all);
            }
Example #19
0
            internal static IApply Dedupe(IApply test)
            {
                ApplyFunc xform = rfs =>
                {
                    var rf   = (IApply)rfs[0];
                    var seen = new object();

                    ApplyFunc nrf = args =>
                    {
                        switch (args.Length)
                        {
                        case 0:
                            return(Funcall(rf));

                        case 1:
                            return(Funcall(rf, args[0]));

                        default:
                            var result = args[0];
                            var input  = args[1];
                            if (FuncallBool(test, seen, input))
                            {
                                return(result);
                            }
                            else
                            {
                                seen = input;
                                return(Apply(rf, args));
                            }
                        }
                    };
                    return(new ApplyWrapper2(nrf));
                };

                return(new ApplyWrapper2(xform));
            }
Example #20
0
            internal static IApply Distinct(IApply test)
            {
                ApplyFunc xform = rfs =>
                {
                    var rf  = (IApply)rfs[0];
                    var bag = new Vector();

                    ApplyFunc nrf = args =>
                    {
                        switch (args.Length)
                        {
                        case 0:
                            return(Funcall(rf));

                        case 1:
                            return(Funcall(rf, args[0]));

                        default:
                            var result = args[0];
                            var input  = args[1];
                            if (Runtime.IndexOf(input, test, bag) == null)
                            {
                                bag.Add(input);
                                return(Apply(rf, args));
                            }
                            else
                            {
                                return(result);
                            }
                        }
                    };
                    return(new ApplyWrapper2(nrf));
                };

                return(new ApplyWrapper2(xform));
            }
Example #21
0
 public static int RunMenu(IEnumerable items, IApply handler)
 {
     return RunMenu(GetStdScr(), items, handler);
 }
Example #22
0
 internal int RunMenu(IEnumerable items, IApply handler)
 {
     var v = new List<string>();
     foreach (var item in items)
     {
         var s = item.ToString();
         if (s.Length > Width)
         {
             s = s.Substring(0, Width);
         }
         v.Add(s.PadRight(Width));
     }
     var offset = 0;
     var cursor = 0;
     System.Func<bool> upArrow = () =>
     {
         if (cursor > 0)
         {
             --cursor;
             return true;
         }
         else if (offset > 0)
         {
             --offset;
             return true;
         }
         else
         {
             return false;
         }
     };
     System.Func<bool> downArrow = () =>
     {
         if (cursor + offset + 1 < v.Count)
         {
             if (cursor + 1 < Height)
             {
                 ++cursor;
                 return true;
             }
             else if (offset + 1 < v.Count)
             {
                 ++offset;
                 return true;
             }
         }
         return false;
     };
     Clear();
     while (true)
     {
         DrawMenu(v, offset, cursor);
         var k = GetKey(false);
         switch (k.KeyData)
         {
             case Keys.LButton:
             {
                 break;
             }
             case Keys.Enter:
             {
                 var choice = offset + cursor;
                 if (handler == null)
                 {
                     return choice;
                 }
                 else
                 {
                     DrawMenu(v, offset, -1);
                     Refresh();
                     if (!Runtime.FuncallBool(handler, choice))
                     {
                         return -1;
                     }
                 }
                 break;
             }
             case Keys.Escape:
             case Keys.Back:
             {
                 return -1;
             }
             case Keys.Home:
             {
                 cursor = offset = 0;
                 break;
             }
             case Keys.PageUp:
             {
                 cursor = 0;
                 for (var i=0; i< Height; ++i)
                 {
                     upArrow();
                 }
                 break;
             }
             case Keys.Up:
             {
                 upArrow();
                 break;
             }
             case Keys.Down:
             case Keys.Tab:
             {
                 downArrow();
                 break;
             }
             case Keys.PageDown:
             {
                 cursor = Height - 1;
                 for (var i=0; i< Height; ++i)
                 {
                     downArrow();
                 }
                 break;
             }
             case Keys.End:
             {
                 while (downArrow())
                 {
                 }
                 break;
             }
         }
     }
 }
Example #23
0
            public static IEnumerable Union(IEnumerable seq1, IEnumerable seq2, IApply test)
            {
                var z = new Vector();

                foreach (object item in ToIter(seq1))
                {
                    var mv = FindItem(z, item, test, null, null);

                    if (mv.Item2 == null)
                    {
                        z.Add(item);
                    }
                }

                foreach (object item in ToIter(seq2))
                {
                    var mv = FindItem(z, item, test, null, null);

                    if (mv.Item2 == null)
                    {
                        z.Add(item);
                    }
                }

                return z;
            }
Example #24
0
            public static object Average(IEnumerable seq, IApply key)
            {
                object result = null;
                int count = 0;
                foreach (object item in ToIter(seq))
                {
                    var val = Funcall(key, item);

                    if (val != null)
                    {
                        ++count;

                        if (result == null)
                        {
                            result = val;
                        }
                        else {
                            result = Add2(result, val);
                        }
                    }
                }

                return result == null ? null : Div(result, count);
            }
Example #25
0
 public static IEnumerable Sort(IEnumerable seq, IApply test, IApply key)
 {
     return MergeSort(AsVector(seq), test, key);
 }
Example #26
0
            public static IEnumerable Reductions(IApply reducer, IEnumerable seq, object seed, IApply key)
            {
                var result = seed;
                foreach (object x in ToIter(seq))
                {
                    if (result == MissingValue)
                    {
                        result = Funcall(key, x);
                    }
                    else {
                        result = Funcall(reducer, result, Funcall(key, x));
                    }

                    yield return result;
                }
            }
Example #27
0
 public static int RunMenu(Window win, IEnumerable items, IApply handler)
 {
     return(win.RunMenu(items, handler));
 }
Example #28
0
 public static int RunMenu(IEnumerable items, IApply handler)
 {
     return(RunMenu(GetStdScr(), items, handler));
 }
Example #29
0
 /// <summary>
 /// Constructs a <see cref="IApplicative"/> predicated on supplied data
 /// </summary>
 /// <param name="apply">A realization of the <see cref="IApply"/> typeclass </param>
 /// <typeparam name="X">The function domain</typeparam>
 /// <typeparam name="CX">A domain container</typeparam>
 /// <typeparam name="CFX">A function container</typeparam>
 /// <typeparam name="CY">A codomain container</typeparam>
 /// <typeparam name="Y">The function codomain</typeparam>
 public static IApplicative <X, CX, CFX, Y, CY> make <X, CX, CFX, Y, CY>(IApply <X, CX, CFX, Y, CY> apply, Pure <X, CX> pure)
     where CX : IContainer <X>
     where CFX : IContainer <Func <X, Y> >
     where CY : IContainer <Y>
 => new Applicative <X, CX, CFX, Y, CY>(apply, pure);
Example #30
0
 public T Apply <T>(IApply config) where T : IComponent
 {
     return((T)this.Apply(config));
 }
Example #31
0
 public static IApply GetClosure(object arg, IApply defaultValue = null)
 {
     return(arg == null ? defaultValue : (IApply)arg);
 }
Example #32
0
        public static Delegate ConvertToDelegate(Type type, IApply closure)
        {
            var expr = GetDelegateExpression(Expression.Constant(closure), type);

            return(expr.Compile());
        }
Example #33
0
 public ApplyLaws(IApply <TF> apply) => _apply = apply;
Example #34
0
 public Bind(IApply <X, CX, CFX, Y, CY> apply, Binder <X, CX, CFX, Y, CY> bind)
 {
     this._apply = apply;
     this._bind  = bind;
 }
Example #35
0
            public static IEnumerable PartitionBy(IApply func, int maxParts, IEnumerable seq)
            {
                object previous = null;
                var all = new Vector();
                Vector v = null;
                foreach (var item in ToIter(seq))
                {
                    if (v == null)
                    {
                        v = new Vector();
                        v.Add(item);
                        previous = Funcall(func, item);
                    }
                    else {
                        var current = Funcall(func, item);
                        if (all.Count + 1 == maxParts || Equal(current, previous))
                        {
                            v.Add(item);
                        }
                        else {
                            all.Add(AsList(v));
                            v = new Vector();
                            previous = current;
                            v.Add(item);
                        }
                    }
                }

                if (v != null)
                {
                    all.Add(AsList(v));
                }
                return all;
            }
Example #36
0
 public static Cons Repeatedly(int count, IApply func)
 {
     return(AsLazyList(SeqBase.Repeatedly(count, func)));
 }
Example #37
0
 public static IEnumerable Remove(IApply predicate, IEnumerable seq, IApply key)
 {
     foreach (object item in ToIter(seq))
     {
         if (!FuncallBool(predicate, Funcall(key, item)))
         {
             yield return item;
         }
     }
 }
Example #38
0
        public static void SetDispatchMacroCharacter(string dispatchChar, string subChar, IApply handler, params object[] kwargs)
        {
            ReadtableHandler2 proc = (reader, ch, arg) =>
            {
                var stream = reader.Stream;
                return(Funcall(handler, stream, ch, arg));
            };

            SetDispatchMacroCharacter(dispatchChar, subChar, proc, kwargs);
        }
Example #39
0
 public static IEnumerable Repeatedly(int count, IApply func)
 {
     if (count < 0)
     {
         while (true)
         {
             yield return Funcall(func);
         }
     }
     else {
         while (count-- > 0)
         {
             yield return Funcall(func);
         }
     }
 }
Example #40
0
 public T Apply <T>(IApply config) where T : BaseItem
 {
     return((T)this.Apply(config));
 }
Example #41
0
            public static void SplitWith(IApply predicate, IEnumerable seq, out Cons left, out Cons right)
            {
                left = null;
                right = null;

                if (seq != null)
                {
                    var iter = seq.GetEnumerator();
                    var v = new Vector();

                    while (iter.MoveNext())
                    {
                        if (FuncallBool(predicate, iter.Current))
                        {
                            v.Add(iter.Current);
                        }
                        else {
                            left = AsList(v);
                            right = MakeCons(iter.Current, iter);
                            return;
                        }
                    }

                    left = AsList(v);
                }
            }
Example #42
0
 public static Prototype AsPrototype(IEnumerable seq, IApply keyFunc, IApply valueFunc)
 {
     var dict = new Prototype();
     foreach (var item in ToIter(seq))
     {
         var k = Funcall(keyFunc, item);
         var v = Funcall(valueFunc, item);
         dict.SetValue(k, v);
     }
     return dict;
 }
Example #43
0
 public static IEnumerable TakeWhile(IApply predicate, IEnumerable seq)
 {
     foreach (var obj in ToIter(seq))
     {
         if (!FuncallBool(predicate, obj))
         {
             break;
         }
         yield return obj;
     }
 }
Example #44
0
 public void Initialize()
 {
     _mapper    = Substitute.For <IApply <CabRide> >();
     _dbContext = new InMemoryDispatchingDbContext(_fixture.Create <string>());
 }
Example #45
0
 protected void AddEditHandler(Keys key, IApply handler)
 {
     EditHandlers[key] = (object)handler;
 }
Example #46
0
            public static IEnumerable ParallelMap(IApply action, IEnumerable seq)
            {
                if (seq == null)
                {
                    return null;
                }
                var seq2 = ConvertToEnumerableObject(seq);
                var seq3 = seq2.AsParallel().AsOrdered();
                var specials = GetCurrentThread().SpecialStack;

                Func<object, object> wrapper = a =>
                {
                    // We want an empty threadcontext because threads may be reused
                    // and already have a broken threadcontext.
                    CurrentThreadContext = new ThreadContext(specials);
                    return Funcall(action, a);
                };

                return seq3.Select(wrapper);
            }
Example #47
0
 internal void AddEditHandler(Keys key, IApply handler)
 {
     editHandlers[key] = handler;
 }
Example #48
0
 public static Cons Repeatedly(IApply func)
 {
     return(AsLazyList(SeqBase.Repeatedly(-1, func)));
 }
Example #49
0
 public static int RunMenu(Window win, IEnumerable items, IApply handler)
 {
     return win.RunMenu(items, handler);
 }
Example #50
0
 public static Cons TakeWhile(IApply predicate, IEnumerable seq)
 {
     return(AsLazyList(SeqBase.TakeWhile(predicate, seq)));
 }
Example #51
0
 public static IEnumerable OnListEnumerator(Cons seq, IApply step)
 {
     while (seq != null)
     {
         yield return seq;
         seq = (Cons)Funcall(step, seq);
     }
 }
Example #52
0
            public static IEnumerable MergeSort(Vector seq, IApply test, IApply key)
            {
                if (seq == null || seq.Count <= 1)
                {
                    return seq;
                }

                int middle = seq.Count / 2;
                Vector left = seq.GetRange(0, middle);
                Vector right = seq.GetRange(middle, seq.Count - middle);
                var left2 = MergeSort(left, test, key);
                var right2 = MergeSort(right, test, key);
                return Merge(left2, right2, test, key);
            }
 public DelayedExpression(IApply code)
 {
     Recipe = code;
     Result = null;
 }
Example #54
0
            public static object Mismatch(IEnumerable seq1, IEnumerable seq2, IApply test, IApply key)
            {
                IEnumerator iter1 = ToIter(seq1).GetEnumerator();
                IEnumerator iter2 = ToIter(seq2).GetEnumerator();
                bool atEnd1 = !iter1.MoveNext();
                bool atEnd2 = !iter2.MoveNext();
                int position = 0;

                while (!atEnd1 && !atEnd2)
                {
                    if (!FuncallBool(test, Funcall(key, iter1.Current), Funcall(key, iter2.Current)))
                    {
                        break;
                    }

                    atEnd1 = !iter1.MoveNext();
                    atEnd2 = !iter2.MoveNext();
                    ++position;
                }

                if (atEnd1 && atEnd2)
                {
                    return null;
                }
                else {
                    return position;
                }
            }
 public static DelayedExpression CreateDelayedExpression(IApply func)
 {
     return new DelayedExpression(func);
 }
Example #56
0
            public static IEnumerable KeepIndexed(IApply func, IEnumerable seq, IApply key)
            {
                var index = -1;

                foreach (object item in ToIter(seq))
                {
                    ++index;
                    var value = Funcall(func, index, Funcall(key, item));
                    if (value != null)
                    {
                        yield return value;
                    }
                }
            }
Example #57
0
 public ApplyWrapper(IApply proc)
 {
     Proc = proc;
 }
Example #58
0
 public static IEnumerable Map(IApply func, IEnumerable[] seqs)
 {
     switch (seqs.Length)
     {
         case 1:
             {
                 var args = new object[1];
                 foreach (var item in ToIter(seqs[0]))
                 {
                     args[0] = item;
                     yield return func.Apply(args);
                 }
                 break;
             }
         case 2:
             {
                 var args = new object[2];
                 var iter1 = ToIter(seqs[0]).GetEnumerator();
                 var iter2 = ToIter(seqs[1]).GetEnumerator();
                 while (iter1.MoveNext() && iter2.MoveNext())
                 {
                     args[0] = iter1.Current;
                     args[1] = iter2.Current;
                     yield return func.Apply(args);
                 }
                 break;
             }
         case 3:
             {
                 var args = new object[3];
                 var iter1 = ToIter(seqs[0]).GetEnumerator();
                 var iter2 = ToIter(seqs[1]).GetEnumerator();
                 var iter3 = ToIter(seqs[2]).GetEnumerator();
                 while (iter1.MoveNext() && iter2.MoveNext() && iter3.MoveNext())
                 {
                     args[0] = iter1.Current;
                     args[1] = iter2.Current;
                     args[2] = iter3.Current;
                     yield return func.Apply(args);
                 }
                 break;
             }
         default:
             {
                 var iter = new UnisonEnumerator(seqs);
                 foreach (Vector item in iter)
                 {
                     yield return func.Apply(AsArray(item));
                 }
                 break;
             }
     }
 }
Example #59
0
 public object Apply(IApply config)
 {
     return(ObjectUtils.Apply(this, config));
 }
Example #60
0
            public static IEnumerable Merge(IEnumerable seq1, IEnumerable seq2, IApply test, IApply key)
            {
                IEnumerator iter1 = seq1.GetEnumerator();
                IEnumerator iter2 = seq2.GetEnumerator();
                bool atEnd1 = !iter1.MoveNext();
                bool atEnd2 = !iter2.MoveNext();

                while (!atEnd1 && !atEnd2)
                {
                    //
                    // put in the first element when it is less than or equal to the second element: stable merge
                    //

                    if (FuncallInt(test, Funcall(key, iter1.Current), Funcall(key, iter2.Current)) <= 0)
                    {
                        yield return iter1.Current;
                        atEnd1 = !iter1.MoveNext();
                    }
                    else {
                        yield return iter2.Current;
                        atEnd2 = !iter2.MoveNext();
                    }
                }

                while (!atEnd1)
                {
                    yield return iter1.Current;
                    atEnd1 = !iter1.MoveNext();
                }

                while (!atEnd2)
                {
                    yield return iter2.Current;
                    atEnd2 = !iter2.MoveNext();
                }
            }