関数潮流(Function Tendency)
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
761
On Slideshare
761
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. js> function add2(x) { return x + 2; }js> add2(5);7js> var f = function(x) { return x + 2; }js> f(8);10js> (function(x) { return x + 2; })(9)11
  • 2. js> function add2(x) { return x + 2; }js> add2(5);7js> var f = function(x) { return x + 2; }js> f(8);10js> (function(x) { return x + 2; })(9)11
  • 3. js> function add2(x) { return x + 2; }js> add2(5);7js> var f = function(x) { return x + 2; }js> f(8);10js> (function(x) { return x + 2; })(9)11
  • 4. js> function add2(x) { return x + 2; }js> add2(5);7js> var f = function(x) { return x + 2; }js> f(8);10js> (function(x) { return x + 2; })(9)11
  • 5. js> function add2(x) { return x + 2; }js> add2(5);7js> var f = function(x) { return x + 2; }js> f(8);10js> (function(x) { return x + 2; })(9)11
  • 6. Func<int, int> f = (x) => x + 2;var f = function(x) { return x + 2; }f = lambda x: x + 2;f = x -> x + 2(fset f (lambda (x) (+ x 2)))
  • 7. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 8. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 9. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 10. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 11. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 12. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 13. Func<string, string> foo(Func<DateTime, string> f) { return x => x.ToUpper() + " " + f(DateTime.Today);}Func<DateTime, string> d = x => x.Year + "/" + x.Month;Func<string, string> c = foo(d);string result = c("oblove"); “OBLOVE 2011/7”
  • 14. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 15. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 16. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 17. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 18. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 19. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 20. int sum(int acc, IEnumerable<int> list) { if (!list.Any()) { return acc; } int head = list.First(); return sum(acc + head, list.Skip(1));}List<int> ls = new List<int> { 3, 5, 8 };int result = sum(0, ls);
  • 21. >>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), s)[C#, JAVA, PYTHON]>>> map(lambda x: len(x), s)[2, 4, 6]
  • 22. >>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), s)[C#, JAVA, PYTHON]>>> map(lambda x: len(x), s)[2, 4, 6]
  • 23. >>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), s)[C#, JAVA, PYTHON]>>> map(lambda x: len(x), s)[2, 4, 6]
  • 24. >>> s = [1, 2, 3, 4, 5, 6]>>> filter(lambda x: x % 2 == 0, s)[2, 4, 6]>>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), filter(lambda x: len(x) > 3, s))[JAVA, PYTHON]
  • 25. >>> s = [1, 2, 3, 4, 5, 6]>>> filter(lambda x: x % 2 == 0, s)[2, 4, 6]>>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), filter(lambda x: len(x) > 3, s))[JAVA, PYTHON]
  • 26. >>> s = [1, 2, 3, 4, 5, 6]>>> filter(lambda x: x % 2 == 0, s)[2, 4, 6]>>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), filter(lambda x: len(x) > 3, s))[JAVA, PYTHON]
  • 27. >>> s = [1, 2, 3, 4, 5, 6]>>> filter(lambda x: x % 2 == 0, s)[2, 4, 6]>>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), filter(lambda x: len(x) > 3, s))[JAVA, PYTHON]
  • 28. >>> s = [3, 4, 5, 7, 9]>>> reduce(lambda x, y: x + y, s, 0)28>>> reduce( lambda x, y: x + (1 if (y % 2 == 0) else 0), s, 0)1
  • 29. >>> s = [3, 4, 5, 7, 9]>>> reduce(lambda x, y: x + y, s, 0)28>>> reduce( lambda x, y: x + (1 if (y % 2 == 0) else 0), s, 0)1
  • 30. >>> s = [3, 4, 5, 7, 9]>>> reduce(lambda x, y: x + y, s, 0)28>>> reduce( lambda x, y: x + (1 if (y % 2 == 0) else 0), s, 0)1
  • 31. >>> import itertools>>> s = [a, b, c, d]>>> zip(s, itertools.count())[(a, 0), (b, 1), (c, 2), (d, 3)]>>> filter(lambda x: x[1] != 1, zip(s, itertools.count()))[(a, 0), (c, 2), (d, 3)]
  • 32. >>> import itertools>>> s = [a, b, c, d]>>> zip(s, itertools.count())[(a, 0), (b, 1), (c, 2), (d, 3)]>>> filter(lambda x: x[1] != 1, zip(s, itertools.count()))[(a, 0), (c, 2), (d, 3)]
  • 33. >>> import itertools>>> s = [a, b, c, d]>>> zip(s, itertools.count())[(a, 0), (b, 1), (c, 2), (d, 3)]>>> filter(lambda x: x[1] != 1, zip(s, itertools.count()))[(a, 0), (c, 2), (d, 3)]
  • 34. >>> [x for x in [1, 2, 3, 4, 5] if (x % 2 != 0)][1, 3, 5]var l = from x in new List<int> { 1, 2, 3, 4, 5 } where x % 2 != 0 select x;
  • 35. >>> [x * 2 for x in [1, 2, 3, 4, 5] if (x % 2 != 0)][2, 6, 10]var l = from x in new List<int> { 1, 2, 3, 4, 5 } where x % 2 != 0 select x * 2;
  • 36. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 37. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 38. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 39. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 40. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 41. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 42. def cor(f): i = 0 while True: i = f(i) yield il = cor(lambda x: x + 4)[l.next() for x in range(0, 3)] [4, 8, 12]
  • 43. IEnumerable<int> cor(Func<int, int> f) { int i = 0; while (true) { i = f(i); yield return i; }}var li = cor(x => x + 4);var ls = from x in li.Take(3) select "<" + x.ToString() + ">"; [“<4>”, “<8>”, “<12>”]
  • 44. import static java.util.Arrays.asList;import static ch.lambdaj.Lambda.*;import static org.hamcrest.Matchers.*;selected = filter(greaterThan(3), asList(1, 2, 3, 4, 5)); [4, 5]List<String> fruits = asList("apple", "orange", "banana");selected = filter(startsWith("a"), fruits); [“apple”]
  • 45. import static java.util.Arrays.asList;import static ch.lambdaj.Lambda.*;import static org.hamcrest.Matchers.*;selected = filter(greaterThan(3), asList(1, 2, 3, 4, 5)); [4, 5]List<String> fruits = asList("apple", "orange", "banana");selected = filter(startsWith("a"), fruits); [“apple”]
  • 46. import static java.util.Arrays.asList;import static ch.lambdaj.Lambda.*;import static org.hamcrest.Matchers.*;selected = filter(greaterThan(3), asList(1, 2, 3, 4, 5)); [4, 5]List<String> fruits = asList("apple", "orange", "banana");selected = filter(startsWith("a"), fruits); [“apple”]
  • 47. import static java.util.Arrays.asList;import static ch.lambdaj.Lambda.*;import static org.hamcrest.Matchers.*;selected = filter(greaterThan(3), asList(1, 2, 3, 4, 5)); [4, 5]List<String> fruits = asList("apple", "orange", "banana");selected = filter(startsWith("a"), fruits); [“apple”]
  • 48. import static java.util.Arrays.asList;import static ch.lambdaj.Lambda.*;import static org.hamcrest.Matchers.*;selected = filter(greaterThan(3), asList(1, 2, 3, 4, 5)); [4, 5]List<String> fruits = asList("apple", "orange", "banana");selected = filter(startsWith("a"), fruits); [“apple”]
  • 49. selected = convert(fruits, new Converter<String, String>() { public String convert(String arg0) { return arg0.toUpperCase(); } }); [“APPLE”, “ORANGE”, “BANANA”]Closure c = closure(); { of(System.out).println(var(String.class));}c.apply("foo");c.each(fruits);
  • 50. selected = convert(fruits, new Converter<String, String>() { public String convert(String arg0) { return arg0.toUpperCase(); } }); [“APPLE”, “ORANGE”, “BANANA”]Closure c = closure(); { of(System.out).println(var(String.class));}c.apply("foo");c.each(fruits);
  • 51. selected = convert(fruits, new Converter<String, String>() { public String convert(String arg0) { return arg0.toUpperCase(); } }); [“APPLE”, “ORANGE”, “BANANA”]Closure c = closure(); { of(System.out).println(var(String.class));}c.apply("foo");c.each(fruits);
  • 52. selected = convert(fruits, new Converter<String, String>() { public String convert(String arg0) { return arg0.toUpperCase(); } }); [“APPLE”, “ORANGE”, “BANANA”]Closure c = closure(); { of(System.out).println(var(String.class));}c.apply("foo");c.each(fruits);
  • 53. selected = convert(fruits, new Converter<String, String>() { public String convert(String arg0) { return arg0.toUpperCase(); } }); [“APPLE”, “ORANGE”, “BANANA”]Closure c = closure(); { of(System.out).println(var(String.class));}c.apply("foo");c.each(fruits);
  • 54. import static fj.data.Array.*;import static fj.function.Integers.*;import fj.data.Array;Array<Integer> a = array(1, 2, 3, 4, 5, 6);Array<Integer> b = a.filter(even).map(add.f(10)); [12, 14, 16]