PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/rocks/Mono.Cecil.Rocks/Functional.cs

http://github.com/jbevain/cecil
C# | 41 lines | 24 code | 8 blank | 9 comment | 2 complexity | d2cfd78e8dad0c12930974666235b102 MD5 | raw file
 1//
 2// Author:
 3//   Jb Evain (jbevain@gmail.com)
 4//
 5// Copyright (c) 2008 - 2015 Jb Evain
 6// Copyright (c) 2008 - 2011 Novell, Inc.
 7//
 8// Licensed under the MIT/X11 license.
 9//
10
11using System;
12using System.Collections.Generic;
13
14namespace Mono.Cecil.Rocks {
15
16	static class Functional {
17
18		public static System.Func<A, R> Y<A, R> (System.Func<System.Func<A, R>, System.Func<A, R>> f)
19		{
20			System.Func<A, R> g = null;
21			g = f (a => g (a));
22			return g;
23		}
24
25		public static IEnumerable<TSource> Prepend<TSource> (this IEnumerable<TSource> source, TSource element)
26		{
27			if (source == null)
28				throw new ArgumentNullException ("source");
29
30			return PrependIterator (source, element);
31		}
32
33		static IEnumerable<TSource> PrependIterator<TSource> (IEnumerable<TSource> source, TSource element)
34		{
35			yield return element;
36
37			foreach (var item in source)
38				yield return item;
39		}
40	}
41}