예제 #1
0
        public static string ToString <T>(this ISequence <T> @this, int n)
        {
            var iterator = @this.Begin();

            return(string.Join(", ", Enumerable.Range(0, n - 1)
                               .Select(x => iterator.Next())
                               .Select(x => x.ToString()).ToArray()));
        }
예제 #2
0
        public static List <T> Take <T>(this ISequence <IOption <T> > @this, int n)
        {
            var iterator = @this.Begin();

            return(Enumerable.Range(0, n - 1)
                   .Select(x => iterator.Next())
                   .Where(option => option.HasValue)
                   .Select(option => option.Value).ToList());
        }
예제 #3
0
        //public static List<T> Take<T>(this ISequence<T> @this, int n)
        //{
        //    var iterator = @this.Begin();
        //    return Enumerable.Range(1, n).Select(x => iterator.Next()).ToList();
        //}

        public static T At <T>(this ISequence <T> @this, long n)
        {
            var iterator = @this.Begin();

            for (long i = 0; i < n; i++)
            {
                iterator.Next();
            }
            return(iterator.Next());
        }
예제 #4
0
        //public static ISequence<TResult> SelectMany<TSource, TCollection, TResult>
        //    (this ISequence<TSource> source,
        //     Func<TSource, ISequence<TCollection>> collectionSelector,
        //     Func<TSource, TCollection, TResult> resultSelector)
        //{
        //    return new FunctionalSequence<TResult>(() =>
        //    {
        //        long g = 0;
        //        return () =>
        //        {
        //            var pair = NtoN2Mapping.GetPair(g++);
        //            var t = source.At(pair.I);
        //            var cs = collectionSelector(t);
        //            var c = cs.At(pair.J);

        //            return resultSelector(t, c);
        //        };
        //    });
        //}

        //public static ISequence<Option<ISequenceGrouping<TKey, Option<TSource>>>> GroupBy<TSource, TKey>(
        //    this ISequence<Option<TSource>> source,
        //    Func<TSource, TKey> keySelector)
        //{
        //    return source.GroupBy(keySelector, t => t);
        //}

// Helper function to zip two regular sequences together
        public static ISequence <TResult> Zip <TSource, TOther, TResult>(
            this ISequence <TSource> @this,
            ISequence <TOther> other,
            Func <TSource, TOther, TResult> mapFunc)
        {
            return(new FunctionalSequence <TResult>(() =>
            {
                var tIter = @this.Begin();
                var sIter = other.Begin();
                return () => mapFunc(tIter.Next(), sIter.Next());
            }));
        }
예제 #5
0
        //public static ISequence<Option<T>> Where<T>(this ISequence<Option<T>> @this, Func<T, bool> filter)
        //{
        //    return @this.Select(t => filter(t) ? new Option<T>(t) : new Option<T>());
        //}

        //public static ISequence<Option<T>> Where<T>(this ISequence<T> @this, Func<T, bool> filter)
        //{
        //    return @this.Select(t => filter(t) ? new Option<T>(t) : new Option<T>());
        //}

        //public static ISequence<S> Select<S, T>(this ISequence<Option<T>> @this, Func<T, S> mapFunc)
        //{
        //    return @this.Where1(t => t.HasValue).Select(o => mapFunc(o.Value));
        //}

        public static ISequence <IOption <T> > Where <T>(this ISequence <IOption <T> > @this, Func <T, bool> filter)
        {
            return(new FunctionalSequence <IOption <T> >(() =>
            {
                var tIter = @this.Begin();
                return () =>
                {
                    var t = tIter.Next();
                    return t.HasValue && filter(t.Value) ? t : Empty <T>();
                };
            }));
        }
예제 #6
0
        //public static T At<T>(this ISequence<T> @this, long n)
        //{
        //    var iterator = @this.Begin();
        //    for (long i = 0; i < n - 1; i++)
        //    {
        //        iterator.Next();
        //    }
        //    return iterator.Next();
        //}

        public static ISequence <IOption <S> > Select <S, T>(this ISequence <IOption <T> > @this, Func <T, S> mapFunc)
        {
            return(new FunctionalSequence <IOption <S> >(() =>
            {
                var tIter = @this.Begin();
                return () =>
                {
                    var t = tIter.Next();
                    return t.HasValue ? FromValue(mapFunc(t.Value)) : Empty <S>();
                };
            }));
        }
예제 #7
0
 public ISequenceIterator <TElement> Begin()
 {
     return(_sequnce.Begin());
 }
예제 #8
0
 public ISequenceIterator <S> Begin()
 {
     return(new SelectSequenceIterator <S, T>(_original.Begin(), _mapFunc));
 }