\u3000\u3000\u56e2\u961f\u5df2\u7ecf\u4ece\u6700\u8fd1\u901a\u8fc7\u7684 SE-0270 \u63d0\u6848\u4e2d\u4e3a\u9884\u89c8\u7248\u6807\u51c6\u5e93\u6dfb\u52a0\u4e86\u529f\u80fd\uff0c\u8be5\u63d0\u6848\u5305\u62ec\u5bf9\u96c6\u5408\u5b50\u8303\u56f4\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982subranges (where:) \u548c moveSubranges (_🇹🇴)\uff0c\u4ee5\u53ca\u652f\u6301\u7684RangeSet\u7c7b\u578b\u3002<\/p>\n
\u3000\u3000\u8981\u5728 Swift Package Manager \u9879\u76ee\u4e2d\u4f7f\u7528\u6807\u51c6\u5e93\u5305\uff0c\u8bf7\u5c06\u5176\u4f5c\u4e3a\u5305\u4f9d\u8d56\u9879\u548c\u76ee\u6807\u4f9d\u8d56\u9879\u6dfb\u52a0\u5230Package.swift\u6587\u4ef6\u4e2d\uff1a<\/p>\n
\n
let package = Package (\r\n name: <\/span>\"<\/span>MyPackage<\/span>\"<\/span>,\r\n dependencies: [\r\n .package (url: <\/span>\"<\/span>https:\/\/github.com\/apple\/swift-standard-library-preview.git<\/span>\"<\/span>, from<\/span>: \"<\/span>0.0.1<\/span>\"<\/span>),\r\n ],\r\n targets: [\r\n .target (\r\n name: <\/span>\"<\/span>MyTarget<\/span>\"<\/span>,\r\n dependencies: [.product (name: <\/span>\"<\/span>StandardLibraryPreview<\/span>\"<\/span>, package: \"<\/span>swift-standard-library-preview<\/span>\"<\/span>)]),\r\n ]\r\n)<\/span><\/pre>\n<\/div>\n\u3000\u4ee5 SE-0270 \u4f5c\u4e3a\u793a\u4f8b\uff1a<\/p>\n
\n
import StandardLibraryPreview\r\n\r\n<\/span>var<\/span> numbers = [10<\/span>, 12<\/span>, -5<\/span>, 14<\/span>, -3<\/span>, -9<\/span>, 15<\/span>]\r\nlet negatives <\/span>= numbers.subranges (where<\/span>: { $0<\/span> < 0<\/span> })\r\n<\/span>\/\/<\/span> numbers[negatives].count == 3<\/span>\r\n\r\nnumbers.moveSubranges (negatives, to: <\/span>0<\/span>)\r\n<\/span>\/\/<\/span> numbers == [-5, -3, -9, 10, 12, 14, 15]<\/span><\/pre>\n<\/div>\n\u3000\u3000\u4f7f\u7528\u72ec\u7acb\u8f6f\u4ef6\u5305<\/p>\n
\u3000\u3000Standard Library Preview \u5305\u6b63\u5728\u6301\u7eed\u5f00\u53d1\u4e2d\uff0c\u5e76\u4e14\u7ef4\u62a4\u7684\u4e3b\u8981\u7248\u672c0\u4ee5\u6307\u793a\u5b83\u5e76\u4e0d\u65e8\u5728\u7a33\u5b9a\u6e90\u3002\u5982\u679c\u60a8\u9700\u8981\u9879\u76ee\u4e2d\u7684\u6e90\u4ee3\u7801\u7a33\u5b9a\u6027\uff0c\u5219\u6bcf\u4e2a\u6279\u51c6\u7684\u6807\u51c6\u5e93\u5efa\u8bae\u4e66\u4e5f\u53ef\u4ee5\u72ec\u7acb\u5305\u88c5\u63d0\u4f9b\u3002\u9884\u89c8\u5305\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u4f1e\u5f62\u5e93\uff0c\u53ef\u91cd\u65b0\u5bfc\u51fa\u6bcf\u4e2a\u5355\u72ec\u7684\u5305\u3002<\/p>\n
\u3000\u3000\u9884\u89c8\u7248\u6807\u51c6\u5e93\u6b63\u5728\u6301\u7eed\u5f00\u53d1\u4e2d\uff0c\u5982\u679c\u4f60\u7684\u9879\u76ee\u5bf9\u4e8e\u4ee3\u7801\u7a33\u5b9a\u6027\u6709\u8981\u6c42\uff0c\u6bcf\u4e2a\u5df2\u901a\u8fc7\u7684\u6807\u51c6\u5e93\u63d0\u6848\u80fd\u591f\u4ee5\u72ec\u7acb\u8f6f\u4ef6\u5305\u7684\u5f62\u5f0f\u63d0\u4f9b\u3002\u4f8b\u5982\uff0cSE-0270 \u63d0\u6848\u7684\u529f\u80fd\u53ef\u901a\u8fc7\u72ec\u7acb\u7684 SE0270_RangeSet \u8f6f\u4ef6\u5305\u83b7\u5f97\u3002\u56e0\u6b64\uff0c\u5982\u679c\u53ea\u9700\u8981\u4f7f\u7528 SE-0270\uff0c\u5219\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3a\u8f6f\u4ef6\u5305\u4f9d\u8d56\u9879\u548c\u76ee\u6807\u4f9d\u8d56\u9879\u6dfb\u52a0\u5230Package.swift\u6587\u4ef6\u4e2d\uff1a<\/p>\n
\n
let package = Package (\r\n name: <\/span>\"<\/span>MyPackage<\/span>\"<\/span>,\r\n dependencies: [\r\n .package (url: <\/span>\"<\/span>https:\/\/github.com\/apple\/swift-se0270-range-set.git<\/span>\"<\/span>, from<\/span>: \"<\/span>1.0.0<\/span>\"<\/span>),\r\n ],\r\n targets: [\r\n .target (\r\n name: <\/span>\"<\/span>MyTarget<\/span>\"<\/span>,\r\n dependencies: [.product (name: <\/span>\"<\/span>SE0270_RangeSet<\/span>\"<\/span>, package: \"<\/span>swift-se0270-range-set<\/span>\"<\/span>)]),\r\n ]\r\n)<\/span><\/pre>\n<\/div>\n\u7136\u540e\u5bfc\u5165 SE-0270\uff1a<\/p>\n
\n
import SE0270_RangeSet\r\n\r\n<\/span>var<\/span> numbers = [10<\/span>, 12<\/span>, -5<\/span>, 14<\/span>, -3<\/span>, -9<\/span>, 15<\/span>]\r\nlet negatives <\/span>= numbers.subranges (where<\/span>: { $0<\/span> < 0<\/span> })\r\n<\/span>\/\/<\/span> numbers[negatives].count == 3<\/span>\r\n\r\nnumbers.moveSubranges (negatives, to: <\/span>0<\/span>)\r\n<\/span>\/\/<\/span> numbers == [-5, -3, -9, 10, 12, 14, 15]<\/span><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u3000\u3000\u56e2\u961f\u5df2\u7ecf\u4ece\u6700\u8fd1\u901a\u8fc7\u7684 SE-0270 \u63d0\u6848\u4e2d\u4e3a\u9884\u89c8\u7248\u6807\u51c6\u5e93\u6dfb\u52a0\u4e86\u529f\u80fd\uff0c\u8be5\u63d0\u6848\u5305\u62ec\u5bf9\u96c6\u5408\u5b50\u8303\u56f4\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982s […]<\/p>\n","protected":false},"author":321,"featured_media":172899,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-172890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/172890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=172890"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/172890\/revisions"}],"predecessor-version":[{"id":172902,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/172890\/revisions\/172902"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/172899"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=172890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=172890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=172890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}