関数潮流(Function Tendency)

640 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
640
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

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
  • 関数潮流(Function Tendency)

    1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 21. >>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), s)[C#, JAVA, PYTHON]>>> map(lambda x: len(x), s)[2, 4, 6]
    22. 22. >>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), s)[C#, JAVA, PYTHON]>>> map(lambda x: len(x), s)[2, 4, 6]
    23. 23. >>> s = [C#, Java, Python ]>>> map(lambda x: x.upper(), s)[C#, JAVA, PYTHON]>>> map(lambda x: len(x), s)[2, 4, 6]
    24. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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]

    ×