Exemplo n.º 1
0
    // C# compiler generates IL with a "leave" instruction outside of a try-catch scenario..
    // we need to treat it as a "br" instruction (NOT LEAVING a protected area).

    private static T FirstOrDefault <T>(T[] source, pred <T> predicate)
    {
        foreach (var s in source)
        {
            if (predicate(s))
            {
                return(s);
            }
        }

        return(default(T));
    }
Exemplo n.º 2
0
        public Stream <T> takeWhile(pred <T> pred)
        {
            state <T, Stream <T> > guard = s =>
            {
                if (s.IsEmpty)
                {
                    return(null);
                }
                else
                {
                    if (!pred(s.Head))
                    {
                        return(null);
                    }
                    else
                    {
                        return(new Tuple <T, Stream <T> >(s.Head, s.Tail));
                    }
                }
            };

            return(unfold(this, guard));
        }