{"id":329689,"date":"2022-02-16T15:01:17","date_gmt":"2022-02-16T15:01:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=329689"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=329689","title":{"rendered":"<span>\u041f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0432 Combine: \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 iOS \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u042f \u2014 \u0418\u0432\u0430\u0435\u0432 \u0417\u0430\u0444\u0430\u0440, iOS \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 <a href=\"http:\/\/usetech.ru\/\">Usetech<\/a>. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043a\u0430\u043a \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Combine \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043a\u0440\u043e\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h3>\n<ul>\n<li>\n<p><code>.first<\/code>, <code>.first(where:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.last<\/code>, <code>.last(where:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.output(at:)<\/code>, <code>.output(in:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.count<\/code><\/p>\n<\/li>\n<li>\n<p><code>.contains<\/code>, <code>.contains(where:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.allSatisfy<\/code><\/p>\n<\/li>\n<li>\n<p><code>.reduce<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>1. first<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.first<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">import Foundation import Combine  var subscriptions = Set&lt;AnyCancellable>()  func firstExample() {     let intPublisher = [10, 20, 100, 200].publisher          intPublisher         .first()         .sink(receiveValue: { print(\"First: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, 10 \u043f\u0440\u0438\u043d\u0442\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e3d\/ee3\/348\/e3dee3348f8b97269996a523186bbf81.png\" width=\"1400\" height=\"639\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e3d\/ee3\/348\/e3dee3348f8b97269996a523186bbf81.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>.first(where)<\/code> \u0432\u0435\u0440\u0441\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"swift\">func firstWhereExample() {     let intPublisher = [23, 33, 50, 27, 101, 108].publisher          intPublisher         .first(where: { $0.isMultiple(of: 2) })         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 50:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/91e\/d9a\/413\/91ed9a41391f77360ea7b69d842d98fd.png\" width=\"1400\" height=\"570\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/91e\/d9a\/413\/91ed9a41391f77360ea7b69d842d98fd.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>2. last<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439:<\/p>\n<pre><code class=\"swift\">func lastExample() {     let intPublisher = [10, 20, 100, 200].publisher          intPublisher         .last()         .sink(receiveValue: { print(\"Last: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/973\/fe7\/c75\/973fe7c75c476ea2c60fa5900b23465b.png\" width=\"1400\" height=\"616\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/973\/fe7\/c75\/973fe7c75c476ea2c60fa5900b23465b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>.last(where:)<\/code> \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<pre><code class=\"swift\">func lastWhereExample() {     let intPublisher = [23, 33, 50, 27, 101, 108].publisher          intPublisher         .last(where: { $0.isMultiple(of: 2) })         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 108 \u0431\u044b\u043b\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ca7\/1e3\/c97\/ca71e3c97e46ca167016d225fa484824.png\" width=\"1400\" height=\"639\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ca7\/1e3\/c97\/ca71e3c97e46ca167016d225fa484824.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>3. output<\/h3>\n<p>\u0412\u0435\u0440\u0441\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, <code>.output(at:)<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443:<\/p>\n<pre><code class=\"swift\">func outputAtExample() {     let stringPublisher = [\"A\", \"B\", \"C\", \"D\"].publisher          stringPublisher         .output(at: 3)         .sink(receiveValue: { print(\"Output: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441 &#8212; 3. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0443\u043a\u0432\u0430 \u00abD\u00bb:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7de\/d3f\/b8f\/7ded3fb8f54ea29f204ca4161fb9f5f3.png\" width=\"1400\" height=\"616\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7de\/d3f\/b8f\/7ded3fb8f54ea29f204ca4161fb9f5f3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0435\u0440\u0441\u0438\u044e <code>.output(in:)<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/609\/bba\/73e\/609bba73e83a6c9511bb8e0b1b7051c9.png\" width=\"1400\" height=\"665\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/609\/bba\/73e\/609bba73e83a6c9511bb8e0b1b7051c9.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>4. count<\/h3>\n<p>\u041a\u0430\u043a \u0438 \u0435\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Swift, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.count<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">func countExample() {     let voidSubject = PassthroughSubject&lt;Void, Never>()          voidSubject         .count()         .sink(receiveValue: { print(\"Total \\($0) events\")})         .store(in: &amp;subscriptions)          voidSubject.send()     voidSubject.send()     voidSubject.send()          voidSubject.send(completion: .finished) }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0442\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>Void<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e 3 \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/889\/99b\/eaf\/88999beafee06090f7f557936893d654.png\" width=\"1400\" height=\"867\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/889\/99b\/eaf\/88999beafee06090f7f557936893d654.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>5. contains<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.contains<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u0438\u043b\u0438 <code>false<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0431\u044b\u043b \u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">func containsExample() {     let letterPublisher = [\"A\", \"B\", \"C\", \"D\", \"E\"].publisher     letterPublisher         .contains(\"Z\")         .sink(receiveValue: {             print(\"Does contain the specified character: \\($0)\")         })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0449\u0435\u043c \u0431\u0443\u043a\u0432\u0443 \u00abZ\u00bb. \u0422\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043d\u0435 \u0431\u044b\u043b\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>false<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cc6\/794\/f6b\/cc6794f6b532437494ebc987151f448c.png\" width=\"1400\" height=\"600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cc6\/794\/f6b\/cc6794f6b532437494ebc987151f448c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code>.contains(where:)<\/code>:<\/p>\n<pre><code class=\"swift\">func containsWhereExample() {     let letterPublisher = [\"a\", \"b\", \"C\", \"d\", \"e\"].publisher     letterPublisher         .contains(where: { $0.first!.isUppercase })         .sink(receiveValue: {             print(\"Does contain an uppercase character: \\($0)\")         })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a <code>letterPublisher<\/code> \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0431\u0443\u043a\u0432\u0443 \u00abC\u00bb, \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f <code>true<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e21\/add\/c4d\/e21addc4d8304d59c00697ebdd3b9055.png\" width=\"1400\" height=\"648\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e21\/add\/c4d\/e21addc4d8304d59c00697ebdd3b9055.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>6. allSatisfy<\/h3>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443 .contains, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.allSatisfy<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>Bool<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e:<\/p>\n<pre><code class=\"swift\">func allSatisfyExample() {     let intPublisher = [3, 9, 27, 81, 244].publisher          intPublisher         .allSatisfy({ $0.isMultiple(of: 3) })         .sink(receiveValue: {             print(\"All numbers are divisible by 3: \\($0)\")         })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>false<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2c9\/f05\/7ab\/2c9f057ab51706b996030083ff640fe7.png\" width=\"1400\" height=\"708\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2c9\/f05\/7ab\/2c9f057ab51706b996030083ff640fe7.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>7. reduce<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, <code>.reduce<\/code>, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0449\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"swift\">func reduceExample() {     let intPublisher = [3, 9, 27, 81, 244].publisher          intPublisher         .reduce(0) { accumulated, value in accumulated + value }         .sink(receiveValue: { print(\"Sum: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 &#8212; 364, \u0441\u0443\u043c\u043c\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/031\/933\/271\/031933271d94ed864083d0374ed662eb.png\" width=\"1400\" height=\"596\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/031\/933\/271\/031933271d94ed864083d0374ed662eb.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.reduce<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0432\u044b\u0434\u0430\u0441\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"swift\">func reduceExample() {     let intPublisher = [3, 9, 27, 81, 244].publisher          intPublisher         .reduce(0, +)         .sink(receiveValue: { print(\"Sum: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<hr\/>\n<h3>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h3>\n<ul>\n<li>\n<p><code>.prepend<\/code><\/p>\n<\/li>\n<li>\n<p><code>.append<\/code><\/p>\n<\/li>\n<li>\n<p><code>.switchToLatest<\/code><\/p>\n<\/li>\n<li>\n<p><code>.merge(with:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.combineLatest<\/code><\/p>\n<\/li>\n<li>\n<p><code>.zip<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>1. prepend<\/h3>\n<p>\u042d\u0442\u0430 \u0433\u0440\u0443\u043f\u043f\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 <code>Publisher<\/code> \u0434\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e <code>Publisher<\/code>:<\/p>\n<pre><code class=\"swift\">import Foundation import Combine  var subscriptions = Set&lt;AnyCancellable>()  func prependOutputExample() {     let stringPublisher = [\"World!\"].publisher          stringPublisher         .prepend(\"Hello\")         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 &#8212; Hello \u0438 World! \u043f\u0440\u0438\u043d\u0442\u044f\u0442\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9f2\/c95\/57e\/9f2c9557e150ea179cc6beddd043f5a7.png\" width=\"1252\" height=\"664\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9f2\/c95\/57e\/9f2c9557e150ea179cc6beddd043f5a7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 <code>Publisher<\/code> \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"swift\">func prependPublisherExample() {     let subject = PassthroughSubject&lt;String, Never>()     let stringPublisher = [\"Break things!\"].publisher          stringPublisher         .prepend(subject)         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          subject.send(\"Run code\")     subject.send(completion: .finished) }<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 (\u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <code>.finished<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.prepend<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u043b):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d80\/dad\/247\/d80dad247878f3b929efd32962389886.png\" width=\"1400\" height=\"849\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d80\/dad\/247\/d80dad247878f3b929efd32962389886.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>2. append<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.append<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <code>.prepend<\/code>, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 <code>Publisher<\/code>:<\/p>\n<pre><code class=\"swift\">func appendOutputExample() {     let stringPublisher = [\"Hello\"].publisher          stringPublisher         .append(\"World!\")         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043a\u0430\u043a Hello \u0438 World! \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/447\/c25\/c80\/447c25c80d1917f18bbc21afb07b8a3f.png\" width=\"1198\" height=\"674\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/447\/c25\/c80\/447c25c80d1917f18bbc21afb07b8a3f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 <code>Publisher<\/code> \u0440\u0430\u043d\u044c\u0448\u0435, \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u043e\u043f\u0446\u0438\u044f \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>.append<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b3\/5bc\/152\/7b35bc15256f088f31a695b185f1bda7.png\" width=\"1382\" height=\"848\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b3\/5bc\/152\/7b35bc15256f088f31a695b185f1bda7.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>3. switchToLatest<\/h3>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.switchToLatest<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0441\u0435\u0440\u0438\u044e <code>Publisher<\/code> \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439:<\/p>\n<pre><code class=\"swift\">func switchToLatestExample() {     let stringSubject1 = PassthroughSubject&lt;String, Never>()     let stringSubject2 = PassthroughSubject&lt;String, Never>()     let stringSubject3 = PassthroughSubject&lt;String, Never>()          let subjects    = PassthroughSubject&lt;PassthroughSubject&lt;String, Never>, Never>()          subjects         .switchToLatest()         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          subjects.send(stringSubject1)          stringSubject1.send(\"A\")          subjects.send(stringSubject2)          stringSubject1.send(\"B\") \/\/ \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e          stringSubject2.send(\"C\")     stringSubject2.send(\"D\")          subjects.send(stringSubject3)          stringSubject2.send(\"E\") \/\/ \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e     stringSubject2.send(\"F\") \/\/ \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e          stringSubject3.send(\"G\")          stringSubject3.send(completion: .finished) }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043a\u043e\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>PassthroughSubject<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>PassthroughSubject<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0442\u0438\u043f\u0430 <code>PassthroughSubject<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c <code>stringSubject1<\/code> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 <code>PassthroughSubject<\/code> .<\/p>\n<\/li>\n<li>\n<p><code>stringSubject1<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 A.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c <code>stringSubject2<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 <code>PassthroughSubject<\/code>, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>stringSubject1<\/code> c \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>stringSubject2<\/code>. \u041f\u043e\u0441\u043b\u0435, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a <code>stringSubject3<\/code>, \u0447\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e <code>PassthroughSubject<\/code> \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442 <code>stringSubject2<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f A, C, D \u0438 G:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/df1\/841\/dc6\/df1841dc6dea1e9e15688ee5a7d5ecd0.png\" width=\"1270\" height=\"802\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/df1\/841\/dc6\/df1841dc6dea1e9e15688ee5a7d5ecd0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 (<code>UITextField<\/code>), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0433\u043e \u043b\u0438\u0431\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0430\u0441\u0441\u043e\u0440\u0442\u0438\u043c\u0435\u043d\u0442\u0435. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0432\u043e\u0434\u0438\u0442, \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441. <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u0435\u0434\u0435\u0442 \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u0432\u0432\u043e\u0434 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c &#8212; \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0441\u043f\u0435\u043b \u0432\u0432\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u043e\u043b\u0435:<\/p>\n<pre><code class=\"swift\">func switchToLatestExample2() {     func isAvailable(query: String) -> Future&lt;Bool, Never> {         return Future { promise in             DispatchQueue.main.asyncAfter(deadline: .now() + 2) {                 promise(.success(Bool.random()))             }         }     }          let searchSubject = PassthroughSubject&lt;String, Never>()          searchSubject         .print(\"subject\")         .map { isAvailable(query: $0) }         .print(\"search\")         .switchToLatest()         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          searchSubject.send(\"Query 1\")     DispatchQueue.main.asyncAfter(deadline: .now() + 1) {         searchSubject.send( \"Query 2\")     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>isAvailable<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>Bool<\/code> \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438.<\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443 <code>.switchToLatest<\/code> \u043c\u044b \u0434\u043e\u0431\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0445\u043e\u0442\u0438\u043c. \u0412\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Bool<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0432\u0443\u0445.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c1c\/df7\/a89\/c1cdf7a89251c1f025ebcdc9e85fc35c.png\" width=\"1400\" height=\"738\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c1c\/df7\/a89\/c1cdf7a89251c1f025ebcdc9e85fc35c.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>4. merge(with:)<\/h3>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>.merge(with:)<\/code> \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 <code>Publisher<\/code>, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e:<\/p>\n<pre><code class=\"swift\">func mergeWithExample() {     let stringSubject1 = PassthroughSubject&lt;String, Never>()     let stringSubject2 = PassthroughSubject&lt;String, Never>()          stringSubject1         .merge(with: stringSubject2)         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          stringSubject1.send(\"A\")          stringSubject2.send(\"B\")          stringSubject2.send(\"C\")          stringSubject1.send(\"D\") }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0434\u0443\u044e\u0449\u0430\u044f\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c35\/9e1\/645\/c359e164558d846ef69917f8e3732838.png\" width=\"956\" height=\"738\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c35\/9e1\/645\/c359e164558d846ef69917f8e3732838.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>5. combineLatest<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.combineLatest<\/code> \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 <code>tuple<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e <code>Publisher<\/code>.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043d\u043e\u043f\u043a\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0439\u0442\u0438 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043a\u0440\u0430\u043d \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u044f\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0430 \u043f\u0430\u0440\u043e\u043b\u044c &#8212; \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u043e\u0441\u044c\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>.combineLatest<\/code>:<\/p>\n<pre><code class=\"swift\">func combineLatestExample() {     let usernameTextField = CurrentValueSubject&lt;String, Never>(\"\")     let passwordTextField = CurrentValueSubject&lt;String, Never>(\"\")          let isButtonEnabled = CurrentValueSubject&lt;Bool, Never>(false)          usernameTextField         .combineLatest(passwordTextField)         .handleEvents(receiveOutput: { (username, password) in             print(\"Username: \\(username), password: \\(password)\")             let isSatisfied = username.count >= 5 &amp;&amp; password.count >= 8             isButtonEnabled.send(isSatisfied)         })         .sink(receiveValue: { _ in })         .store(in: &amp;subscriptions)          isButtonEnabled         .sink { print(\"isButtonEnabled: \\($0)\") }         .store(in: &amp;subscriptions)          usernameTextField.send(\"user\")     usernameTextField.send(\"user12\")          passwordTextField.send(\"12\")     passwordTextField.send(\"12345678\") }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e <code>usernameTextField<\/code> \u0438 <code>passwordTextField<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 user12 \u0438 12345678 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u0438 \u043a\u043d\u043e\u043f\u043a\u0430 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9a2\/1ba\/b5f\/9a21bab5f524c6e7772219ed2695c5bf.png\" width=\"1350\" height=\"908\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9a2\/1ba\/b5f\/9a21bab5f524c6e7772219ed2695c5bf.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>6. zip<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.zip<\/code> \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442 \u043a\u0430\u0436\u0434\u043e\u0433\u043e <code>Publisher<\/code>. \u0421\u043a\u0430\u0436\u0435\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u043b\u0438 \u043e\u0431\u0430 <code>Publisher<\/code> \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Int<\/code>:<\/p>\n<pre><code class=\"swift\">func zipExample() {     let intSubject1 = PassthroughSubject&lt;Int, Never>()     let intSubject2 = PassthroughSubject&lt;Int, Never>()          let foundIdenticalPairSubject = PassthroughSubject&lt;Bool, Never>()          intSubject1         .zip(intSubject2)         .handleEvents(receiveOutput: { (value1, value2) in             print(\"value1: \\(value1), value2: \\(value2)\")             let isIdentical = value1 == value2             foundIdenticalPairSubject.send(isIdentical)         })         .sink(receiveValue: { _ in })         .store(in: &amp;subscriptions)          foundIdenticalPairSubject         .sink(receiveValue: { print(\"is identical: \\($0)\") })         .store(in: &amp;subscriptions)          intSubject1.send(0)     intSubject1.send(1)          intSubject2.send(4)          intSubject1.send(6)     intSubject2.send(1)     intSubject2.send(7)          intSubject2.send(9) \/\/ Not displayed, as its pair is not yet emitted }<\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>intSubject1<\/code> \u0438 <code>intSubject2<\/code>:<\/p>\n<ul>\n<li>\n<p>0 \u0438 4<\/p>\n<\/li>\n<li>\n<p>1 \u0438 1<\/p>\n<\/li>\n<li>\n<p>6 \u0438 7<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, 9, \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>intSubject1<\/code> \u0435\u0449\u0435 \u043d\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2bf\/ffb\/9c5\/2bfffb9c5c79d4e0f06c62df1051a67b.png\" width=\"1400\" height=\"715\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2bf\/ffb\/9c5\/2bfffb9c5c79d4e0f06c62df1051a67b.png\"\/><figcaption><\/figcaption><\/figure>\n<hr\/>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435! \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c Combine.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/usetech\/blog\/651947\/\"> https:\/\/habr.com\/ru\/company\/usetech\/blog\/651947\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u042f \u2014 \u0418\u0432\u0430\u0435\u0432 \u0417\u0430\u0444\u0430\u0440, iOS \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 <a href=\"http:\/\/usetech.ru\/\">Usetech<\/a>. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043a\u0430\u043a \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Combine \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043a\u0440\u043e\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h3>\n<ul>\n<li>\n<p><code>.first<\/code>, <code>.first(where:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.last<\/code>, <code>.last(where:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.output(at:)<\/code>, <code>.output(in:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.count<\/code><\/p>\n<\/li>\n<li>\n<p><code>.contains<\/code>, <code>.contains(where:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.allSatisfy<\/code><\/p>\n<\/li>\n<li>\n<p><code>.reduce<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>1. first<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.first<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">import Foundation import Combine  var subscriptions = Set&lt;AnyCancellable>()  func firstExample() {     let intPublisher = [10, 20, 100, 200].publisher          intPublisher         .first()         .sink(receiveValue: { print(\"First: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, 10 \u043f\u0440\u0438\u043d\u0442\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>.first(where)<\/code> \u0432\u0435\u0440\u0441\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"swift\">func firstWhereExample() {     let intPublisher = [23, 33, 50, 27, 101, 108].publisher          intPublisher         .first(where: { $0.isMultiple(of: 2) })         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 50:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>2. last<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439:<\/p>\n<pre><code class=\"swift\">func lastExample() {     let intPublisher = [10, 20, 100, 200].publisher          intPublisher         .last()         .sink(receiveValue: { print(\"Last: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>.last(where:)<\/code> \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<pre><code class=\"swift\">func lastWhereExample() {     let intPublisher = [23, 33, 50, 27, 101, 108].publisher          intPublisher         .last(where: { $0.isMultiple(of: 2) })         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 108 \u0431\u044b\u043b\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0439 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0443:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>3. output<\/h3>\n<p>\u0412\u0435\u0440\u0441\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, <code>.output(at:)<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443:<\/p>\n<pre><code class=\"swift\">func outputAtExample() {     let stringPublisher = [\"A\", \"B\", \"C\", \"D\"].publisher          stringPublisher         .output(at: 3)         .sink(receiveValue: { print(\"Output: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441 &#8212; 3. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0443\u043a\u0432\u0430 \u00abD\u00bb:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0435\u0440\u0441\u0438\u044e <code>.output(in:)<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>4. count<\/h3>\n<p>\u041a\u0430\u043a \u0438 \u0435\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Swift, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.count<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">func countExample() {     let voidSubject = PassthroughSubject&lt;Void, Never>()          voidSubject         .count()         .sink(receiveValue: { print(\"Total \\($0) events\")})         .store(in: &amp;subscriptions)          voidSubject.send()     voidSubject.send()     voidSubject.send()          voidSubject.send(completion: .finished) }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0442\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>Void<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e 3 \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>5. contains<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.contains<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u0438\u043b\u0438 <code>false<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0431\u044b\u043b \u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"swift\">func containsExample() {     let letterPublisher = [\"A\", \"B\", \"C\", \"D\", \"E\"].publisher     letterPublisher         .contains(\"Z\")         .sink(receiveValue: {             print(\"Does contain the specified character: \\($0)\")         })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0449\u0435\u043c \u0431\u0443\u043a\u0432\u0443 \u00abZ\u00bb. \u0422\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043d\u0435 \u0431\u044b\u043b\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>false<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code>.contains(where:)<\/code>:<\/p>\n<pre><code class=\"swift\">func containsWhereExample() {     let letterPublisher = [\"a\", \"b\", \"C\", \"d\", \"e\"].publisher     letterPublisher         .contains(where: { $0.first!.isUppercase })         .sink(receiveValue: {             print(\"Does contain an uppercase character: \\($0)\")         })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a <code>letterPublisher<\/code> \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0431\u0443\u043a\u0432\u0443 \u00abC\u00bb, \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f <code>true<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>6. allSatisfy<\/h3>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443 .contains, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.allSatisfy<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>Bool<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>true<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e:<\/p>\n<pre><code class=\"swift\">func allSatisfyExample() {     let intPublisher = [3, 9, 27, 81, 244].publisher          intPublisher         .allSatisfy({ $0.isMultiple(of: 3) })         .sink(receiveValue: {             print(\"All numbers are divisible by 3: \\($0)\")         })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>false<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>7. reduce<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, <code>.reduce<\/code>, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0449\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"swift\">func reduceExample() {     let intPublisher = [3, 9, 27, 81, 244].publisher          intPublisher         .reduce(0) { accumulated, value in accumulated + value }         .sink(receiveValue: { print(\"Sum: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 &#8212; 364, \u0441\u0443\u043c\u043c\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.reduce<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0432\u044b\u0434\u0430\u0441\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"swift\">func reduceExample() {     let intPublisher = [3, 9, 27, 81, 244].publisher          intPublisher         .reduce(0, +)         .sink(receiveValue: { print(\"Sum: \\($0)\") })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<hr\/>\n<h3>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h3>\n<ul>\n<li>\n<p><code>.prepend<\/code><\/p>\n<\/li>\n<li>\n<p><code>.append<\/code><\/p>\n<\/li>\n<li>\n<p><code>.switchToLatest<\/code><\/p>\n<\/li>\n<li>\n<p><code>.merge(with:)<\/code><\/p>\n<\/li>\n<li>\n<p><code>.combineLatest<\/code><\/p>\n<\/li>\n<li>\n<p><code>.zip<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>1. prepend<\/h3>\n<p>\u042d\u0442\u0430 \u0433\u0440\u0443\u043f\u043f\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 <code>Publisher<\/code> \u0434\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e <code>Publisher<\/code>:<\/p>\n<pre><code class=\"swift\">import Foundation import Combine  var subscriptions = Set&lt;AnyCancellable>()  func prependOutputExample() {     let stringPublisher = [\"World!\"].publisher          stringPublisher         .prepend(\"Hello\")         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 &#8212; Hello \u0438 World! \u043f\u0440\u0438\u043d\u0442\u044f\u0442\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 <code>Publisher<\/code> \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"swift\">func prependPublisherExample() {     let subject = PassthroughSubject&lt;String, Never>()     let stringPublisher = [\"Break things!\"].publisher          stringPublisher         .prepend(subject)         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          subject.send(\"Run code\")     subject.send(completion: .finished) }<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 (\u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <code>.finished<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.prepend<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u043b):<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>2. append<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.append<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <code>.prepend<\/code>, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 <code>Publisher<\/code>:<\/p>\n<pre><code class=\"swift\">func appendOutputExample() {     let stringPublisher = [\"Hello\"].publisher          stringPublisher         .append(\"World!\")         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions) }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043a\u0430\u043a Hello \u0438 World! \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 <code>Publisher<\/code> \u0440\u0430\u043d\u044c\u0448\u0435, \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u043e\u043f\u0446\u0438\u044f \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>.append<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>3. switchToLatest<\/h3>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>.switchToLatest<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0441\u0435\u0440\u0438\u044e <code>Publisher<\/code> \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439:<\/p>\n<pre><code class=\"swift\">func switchToLatestExample() {     let stringSubject1 = PassthroughSubject&lt;String, Never>()     let stringSubject2 = PassthroughSubject&lt;String, Never>()     let stringSubject3 = PassthroughSubject&lt;String, Never>()          let subjects    = PassthroughSubject&lt;PassthroughSubject&lt;String, Never>, Never>()          subjects         .switchToLatest()         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          subjects.send(stringSubject1)          stringSubject1.send(\"A\")          subjects.send(stringSubject2)          stringSubject1.send(\"B\") \/\/ \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e          stringSubject2.send(\"C\")     stringSubject2.send(\"D\")          subjects.send(stringSubject3)          stringSubject2.send(\"E\") \/\/ \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e     stringSubject2.send(\"F\") \/\/ \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e          stringSubject3.send(\"G\")          stringSubject3.send(completion: .finished) }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043a\u043e\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>PassthroughSubject<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>PassthroughSubject<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0442\u0438\u043f\u0430 <code>PassthroughSubject<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c <code>stringSubject1<\/code> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 <code>PassthroughSubject<\/code> .<\/p>\n<\/li>\n<li>\n<p><code>stringSubject1<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 A.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c <code>stringSubject2<\/code> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 <code>PassthroughSubject<\/code>, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>stringSubject1<\/code> c \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>stringSubject2<\/code>. \u041f\u043e\u0441\u043b\u0435, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a <code>stringSubject3<\/code>, \u0447\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e <code>PassthroughSubject<\/code> \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442 <code>stringSubject2<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f A, C, D \u0438 G:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 (<code>UITextField<\/code>), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a\u043e\u0433\u043e \u043b\u0438\u0431\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0430\u0441\u0441\u043e\u0440\u0442\u0438\u043c\u0435\u043d\u0442\u0435. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0432\u043e\u0434\u0438\u0442, \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441. <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u0435\u0434\u0435\u0442 \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u0432\u0432\u043e\u0434 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c &#8212; \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0441\u043f\u0435\u043b \u0432\u0432\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u043e\u043b\u0435:<\/p>\n<pre><code class=\"swift\">func switchToLatestExample2() {     func isAvailable(query: String) -> Future&lt;Bool, Never> {         return Future { promise in             DispatchQueue.main.asyncAfter(deadline: .now() + 2) {                 promise(.success(Bool.random()))             }         }     }          let searchSubject = PassthroughSubject&lt;String, Never>()          searchSubject         .print(\"subject\")         .map { isAvailable(query: $0) }         .print(\"search\")         .switchToLatest()         .sink(receiveValue: { print($0) })         .store(in: &amp;subscriptions)          searchSubject.send(\"Query 1\")     DispatchQueue.main.asyncAfter(deadline: .now() + 1) {         searchSubject.send( \"Query 2\")     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>isAvailable<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>Bool<\/code> \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438.<\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443 <code>.switchToLatest<\/code> \u043c\u044b \u0434\u043e\u0431\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0442\u043e\u0433\u043e, \u0447\u0435\u0433\u043e \u0445\u043e\u0442\u0438\u043c. \u0412\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>Bool<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0432\u0443\u0445.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>4. merge(with:)<\/h3>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>.merge(<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-329689","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=329689"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329689\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=329689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=329689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=329689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}