{"id":955,"date":"2026-01-25T07:49:35","date_gmt":"2026-01-25T07:49:35","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=955"},"modified":"2026-01-25T07:49:36","modified_gmt":"2026-01-25T07:49:36","slug":"%d1%87%d1%82%d0%be-%d0%b4%d0%b5%d0%bb%d0%b0%d0%b5%d1%82-%d0%be%d0%bf%d0%b5%d1%80%d0%b0%d1%82%d0%be%d1%80-collect-%d0%bc%d0%be%d0%b6%d0%bd%d0%be-%d0%bb%d0%b8-%d0%b2%d1%8b%d0%b7%d0%b2%d0%b0%d1%82%d1%8c","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=955","title":{"rendered":"\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 collect? \u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438?"},"content":{"rendered":"\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>collect<\/code> \u0432 <code>Flow<\/code> (\u0438 <code>StateFlow<\/code>, <code>SharedFlow<\/code>) \u2014 \u044d\u0442\u043e <strong>\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/strong>, \u0431\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e <code>Flow<\/code> <strong>\u043d\u0435 \u043d\u0430\u0447\u043d\u0451\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>collect<\/code><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nflowOf(1, 2, 3).collect { value -&gt;\n    println(value)\n}\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><code>collect {}<\/code> \u2014 \u044d\u0442\u043e <strong>\u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430<\/strong> \u043d\u0430 <code>Flow<\/code><\/li>\n\n\n\n<li>\u043e\u043d <strong>\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 producer<\/strong>, \u0438 \u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0448\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0438\u0445 \u044d\u043c\u0438\u0441\u0441\u0438\u0438<\/li>\n\n\n\n<li>\u0431\u0435\u0437 <code>collect<\/code> \u2014 <code>flow {}<\/code> \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0430\u0447\u043d\u0451\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 (\u043e\u043d \u0445\u043e\u043b\u043e\u0434\u043d\u044b\u0439!)<\/li>\n\n\n\n<li>\u0410\u043d\u0430\u043b\u043e\u0433 \u0432 Rx: <code>subscribe {}<\/code><\/li>\n\n\n\n<li>\u0410\u043d\u0430\u043b\u043e\u0433 \u0432 Java Streams: <code>.forEach {}<\/code><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><code>collect<\/code> \u2014 suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/h4>\n\n\n\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442: \u0442\u044b <strong>\u043d\u0435 \u043c\u043e\u0436\u0435\u0448\u044c<\/strong> \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>collect()<\/code> \u0438\u0437 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 <code>suspend<\/code> \u0438\u043b\u0438 <code>coroutineScope<\/code>. \u041f\u043e\u0447\u0435\u043c\u0443 <code>collect<\/code> \u2014 suspend? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <strong>\u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e<\/strong><\/li>\n\n\n\n<li><code>Flow<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <code>delay<\/code>, <code>withContext<\/code>, <code>emit<\/code>, \u0438 \u0442.\u0434.<\/li>\n\n\n\n<li><code>collect<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b <strong>\u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong> \u043f\u043e\u0442\u043e\u043a<\/li>\n<\/ul>\n\n\n\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e collect() \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0439 suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 scope.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 collect \u0432 Flow (\u0438 StateFlow, SharedFlow) \u2014 \u044d\u0442\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u0431\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e Flow \u043d\u0435 \u043d\u0430\u0447\u043d\u0451\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 collect collect \u2014 suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442: \u0442\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0448\u044c \u0432\u044b\u0437\u0432\u0430\u0442\u044c collect() \u0438\u0437 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 suspend \u0438\u043b\u0438 coroutineScope. \u041f\u043e\u0447\u0435\u043c\u0443 collect \u2014 suspend? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e: \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e collect() \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0439 suspend-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 scope.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,21],"tags":[],"class_list":["post-955","post","type-post","status-publish","format-standard","hentry","category-coroutines","category-kotlin"],"_links":{"self":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=955"}],"version-history":[{"count":1,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/955\/revisions"}],"predecessor-version":[{"id":956,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/955\/revisions\/956"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}