Last active
December 15, 2015 08:29
-
-
Save miya2000/5231424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace QueryTest | |
{ | |
[TestClass] | |
public class QueryTest | |
{ | |
[TestMethod] | |
public void Test1() | |
{ | |
var r = | |
from n in 1 | |
from o in n * 10 | |
from p in o * 10 | |
from q in p * 10 | |
select n + o + p + q; | |
r.Is(1111); | |
var rr = 1 | |
.SelectMany(n => n * 10, (n, o) => new { n, o }) | |
.SelectMany(no => no.o * 10, (no, p) => new { no, p }) | |
.SelectMany(nop => nop.p * 10, (nop, q) => nop.no.n + nop.no.o + nop.p + q); | |
rr.Is(1111); | |
} | |
} | |
public static class Ex | |
{ | |
public static U Select<T, U>(this T x, Func<T, U> f) | |
{ | |
return f(x); | |
} | |
public static V SelectMany<T, U, V>(this T x, Func<T, U> f, Func<T, U, V> g) | |
{ | |
return g(x, f(x)); | |
// こっちの方がわかりやすい? | |
//return g(x, x.Select(f)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment