{"id":1138,"date":"2023-03-16T21:57:01","date_gmt":"2023-03-16T13:57:01","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1138"},"modified":"2023-04-29T09:59:04","modified_gmt":"2023-04-29T01:59:04","slug":"functional-programming-in-dart","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/16\/functional-programming-in-dart\/","title":{"rendered":"Dart\u4e2d\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b"},"content":{"rendered":"<p>\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u505a\u5230\uff1a<\/p>\n<ul>\n<li>\u5c06\u51fd\u6570\u5f53\u505a\u53c2\u6570\u8fdb\u884c\u4f20\u9012<\/li>\n<li>\u5c06\u51fd\u6570\u76f4\u63a5\u8d4b\u503c\u7ed9\u53d8\u91cf<\/li>\n<li>\u5bf9\u51fd\u6570\u8fdb\u884c\u89e3\u6784\uff0c\u53ea\u4f20\u9012\u7ed9\u51fd\u6570\u4e00\u90e8\u5206\u53c2\u6570\u6765\u8c03\u7528\u5b83\uff0c\u8ba9\u5b83\u8fd4\u56de\u4e00\u4e2a\u51fd\u6570\u53bb\u5904\u7406\u5269\u4e0b\u7684\u53c2\u6570\uff08\u4e5f\u88ab\u79f0\u4e3a\u67ef\u91cc\u5316\uff09<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u88ab\u5f53\u4f5c\u4e3a\u5e38\u91cf\u7684\u533f\u540d\u51fd\u6570\uff0c\u4e5f\u88ab\u79f0\u4e3a lambda\u8868\u8fbe\u5f0f<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<p>\u5728 Dart\u4e2d\uff0c\u6bcf\u4e2a\u51fd\u6570\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5e76\u4e14\u6bcf\u4e2a\u51fd\u6570\u90fd\u6709\u5b83\u7684\u7c7b\u578bFunction\uff0c\u8fd9\u610f\u5473\u7740\u6240\u6709\u51fd\u6570\u90fd\u53ef\u4ee5\u652f\u6301\u8d4b\u503c\u64cd\u4f5c\uff0c\u4ee5\u53ca\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u7684\u51fd\u6570\u3002<\/p>\n<h2>\u547d\u4ee4\u5f0f\u7f16\u7a0b\u65b9\u5f0f<\/h2>\n<pre><code class=\"language-dart\">String scream(int length) =&gt; &quot;A${&#039;a&#039; * length}h!&quot;;\n\nmain() {\n  final values = [1, 2, 3, 5, 10, 50];\n  for (var length in values) {\n    print(scream(length));\n  }\n}<\/code><\/pre>\n<h2>\u51fd\u6570\u5f0f\u7f16\u7a0b\u65b9\u5f0f<\/h2>\n<pre><code class=\"language-dart\">String scream(int length) =&gt; &quot;A${&#039;a&#039; * length}h!&quot;;\n\nmain() {\n  final values = [1, 2, 3, 5, 10, 50];\n  values.map(scream).forEach(print);\n}<\/code><\/pre>\n<h2>\u51fd\u6570\u5f0f\u7684\u8fed\u4ee3\u7279\u6027<\/h2>\n<p>dart:collection \u5e93\u4e2d\u7684 List \u548c Iterable \u652f\u6301 fold, where, join, skip \u7b49\u51fd\u6570\u5f0f\u65b9\u6cd5\uff0c\u53e6\u5916 Dart \u8fd8\u652f\u6301 Map \u548c Set \u7c7b\u578b\u3002<\/p>\n<pre><code class=\"language-dart\">String scream(int length) =&gt; &quot;A${&#039;a&#039; * length}h!&quot;;\n\nmain() {\n  final values = [1, 2, 3, 5, 10, 50];\n  values.skip(1).take(3).map(scream).forEach(print);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u505a\u5230\uff1a \u5c06\u51fd\u6570\u5f53\u505a\u53c2\u6570\u8fdb\u884c\u4f20\u9012 \u5c06\u51fd\u6570\u76f4\u63a5\u8d4b\u503c\u7ed9\u53d8\u91cf \u5bf9\u51fd\u6570\u8fdb\u884c\u89e3\u6784\uff0c\u53ea\u4f20\u9012\u7ed9\u51fd\u6570\u4e00\u90e8\u5206\u53c2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[304],"class_list":["post-1138","post","type-post","status-publish","format-standard","hentry","category-java","tag-dart"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1138"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1138\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}