예제 #1
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;
                }
                }
            }
예제 #2
0
파일: seq.cs 프로젝트: lkonings/kiezellisp
 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());
     }
 }