{"id":151648,"date":"2020-08-25T18:01:14","date_gmt":"2020-08-25T10:01:14","guid":{"rendered":"http:\/\/4563.org\/?p=151648"},"modified":"2020-08-25T18:01:14","modified_gmt":"2020-08-25T10:01:14","slug":"%e5%85%b3%e4%ba%8e-go-linq-%e5%92%8c-rxgo-%e5%81%9a%e6%95%b0%e6%8d%ae%e7%bb%9f%e8%ae%a1%e8%bf%98%e6%98%af-go-linq-%e6%96%b9%e4%be%bf%e4%b8%80%e7%82%b9","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=151648","title":{"rendered":"\u5173\u4e8e go-linq \u548c RxGo, \u505a\u6570\u636e\u7edf\u8ba1\u8fd8\u662f go-linq \u65b9\u4fbf\u4e00\u70b9"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5173\u4e8e go-linq \u548c RxGo, \u505a\u6570\u636e\u7edf\u8ba1\u8fd8\u662f go-linq \u65b9\u4fbf\u4e00\u70b9               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : prenwang <\/span>  <span><i><\/i> 13<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u8fd9\u4e24\u4e2a\u5e93\u90fd\u4e0d\u9519, \u5f00\u53d1\u6d3b\u8dc3, go-linq \u6765\u81ea Google \u5458\u5de5, RxGo \u6765\u81ea ReactiveX \u5b98\u65b9, \u80cc\u666f\u90fd\u4e0d\u9519.<\/p>\n<p>ReactiveX \u7b97\u662f linq \u7684\u6269\u5c55, RxGo \u7684\u8986\u76d6\u573a\u666f\u8981\u66f4\u5e7f\u6cdb\u4e00\u70b9, \u6269\u5c55\u6027\u66f4\u5f3a, \u5e76\u53d1\u7684\u4f7f\u7528\u4e5f\u5f88\u4fbf\u6377, \u5f53\u7136\u590d\u6742\u6027\u4e5f\u589e\u52a0\u4e86\u4e0d\u5c11,<\/p>\n<p>RxGo \u7684 GroupBY \u8bbe\u8ba1\u7684\u5f88\u5947\u602a, \u5206\u7ec4\u7684 KEY \u548c\u5206\u7ec4\u7684\u6570\u91cf\u8fd8\u8981\u53e6\u5916\u8ba1\u7b97:<\/p>\n<pre><code> type Cat struct {   Name  string   Value string  }  items := []Cat{   {Name: \"a\", Value: \"asdf\"},   {Name: \"a\", Value: \"sdf432\"},   {Name: \"b\", Value: \"sdf342\"},   {Name: \"b\", Value: \"vvvv\"},   {Name: \"c\", Value: \"ccc\"},  }  keys, _ := rxgo.Just(items)().Map(func(_ context.Context, i interface{}) (interface{}, error) {   return i.(Cat).Name, nil  }).Distinct(func(_ context.Context, i interface{}) (interface{}, error) {   return i, nil  }).ToSlice(0)   list := &amp;arraylist.List{}  list.Add(keys...)   observable := rxgo.Just(items)().GroupBy(len(keys), func(item rxgo.Item) int {   return list.IndexOf(item.V.(Cat).Name)  }, rxgo.WithBufferedChannel(5))   for i := range observable.Observe() {   fmt.Println(\"New observable:\")    for i := range i.V.(rxgo.Observable).Observe() {    fmt.Printf(\"item: %vn\", i.V)   }  } <\/code><\/pre>\n<p>RxJava \u548c RxJs \u7b49\u8fd8\u662f\u76f4\u63a5\u6839\u636e\u4e00\u4e2a\u5c5e\u6027\u5206\u7ec4, go-linq \u4e5f\u662f\u5982\u6b64, \u8fd9\u4e00\u70b9\u611f\u89c9\u4e0d\u592a\u559c\u6b22.<\/p>\n<p>RxGo \u662f\u57fa\u4e8e\u6d41\u5904\u7406, \u4e0d\u63d0\u4f9b\u76f4\u63a5\u7684\u6392\u5e8f\u51fd\u6570, \u9700\u8981\u81ea\u5df1\u53bb\u6269\u5c55.<\/p>\n<p>RxGo \u6709\u5b8c\u5584\u7684\u9519\u8bef\u5904\u7406\u673a\u5236, go-linq \u7f3a, \u4f46\u4e5f\u56e0\u6b64, \u5bf9\u8fc7\u7a0b\u548c\u7ed3\u679c\u5904\u7406\u663e\u5f97\u7e41\u7410,<\/p>\n<p>\u5728\u7eaf\u7cb9\u7684\u6570\u636e\u96c6\u7edf\u8ba1\u4e0a go-linq \u8981\u66f4\u65b9\u4fbf\u4e00\u70b9, \u51fd\u6570\u7684\u4f7f\u7528\u66f4\u4fbf\u6377\u4e00\u70b9, \u4fdd\u8bc1\u6570\u636e\u96c6\u5408\u7684\u4e25\u8c28\u524d\u63d0\u4e0b, \u4f7f\u7528 go-linq \u8db3\u591f.<\/p>\n<p>RxGo \u53ef\u4ee5\u5e94\u7528\u5230\u66f4\u590d\u6742\u7684\u573a\u666f\u53bb.<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3063359\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : petelin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u6709\u8303\u6027\u90fd\u592a\u4e11\u4e86 \u7b49\u7740\u51fa\u6765\u4e86\u5728\u73a9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3063360\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : prenwang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u4f60\u8981\u597d\u770b go-linq \u6709\u4f2a\u6cdb\u578b, \u6bd4\u771f\u6b63\u7684\u6cdb\u578b\u8fd8\u597d\u770b, \u6027\u80fd\u51cf\u5f31 5-10 \u500d(\u4ecd\u7136\u53ef\u4ee5\u63a5\u53d7, \u6bd4 python \u8fd8\u662f\u5feb\u5f88\u591a\u5bf9\u5427)<\/p>\n<p>squares := []int{}<\/p>\n<p>Range(1, 10).SelectT(func(x int) int { return x * x } ). ToSlice(&amp;squares)<\/p>\n<p>go-linq \u975e\u6cdb\u578b<\/p>\n<p>squares := []int{}<\/p>\n<p>Range(1, 10).Select( func(x interface{}) interface{} { return x.(int) * x.(int) } ).ToSlice(&amp;squares)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3063361\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : prenwang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             linq \u7684\u573a\u666f, \u5bf9\u6cdb\u578b\u786e\u5b9e\u5f88\u671f\u5f85, \u8d85\u5927\u6570\u636e\u96c6, \u5e94\u8be5\u63d0\u5347\u4e0d\u6b62 10 \u500d\u6027\u80fd<\/p>\n<p>squares := []int{}<\/p>\n<p>Range(1, 10).SelectT(func(type int)(x int) int { return x * x } ). ToSlice(&amp;squares)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3063362\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liprais <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6570\u636e\u653e\u4e0d\u8fdb\u5185\u5b58\u5f53\u573a\u6b47\u83dc\uff0c10 \u500d\u6027\u80fd\u662f\u8111\u8865\u7684\u4e48                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3063363\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jamiesun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ec5\u9488\u5bf9\u5185\u5b58\u4e2d\u5904\u7406\u7684\u6570\u636e\u96c6\u800c\u8a00                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3063364\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jamiesun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c31\u7b97\u662f\u5206\u5e03\u5f0f map reduce\uff0c\u8282\u70b9\u4e0d\u90fd\u662f\u5728\u5185\u5b58\u4e2d\u5904\u7406\u90e8\u5206\u6570\u636e\u96c6\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e go-linq \u548c RxGo&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/151648"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151648"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/151648\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151648"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}