{"id":346522,"date":"2023-03-09T15:01:24","date_gmt":"2023-03-09T15:01:24","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=346522"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=346522","title":{"rendered":"<span>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (pattern matching)<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h1 id=\"obrabotka-isklyucheniy-v-java-s-ispolzovaniem-sopostavleniya-s-obrazcom-pattern-matching\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (pattern matching).<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u0442\u0435\u0439 <\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/676852\/\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435<\/a> \u0438 <\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/687954\/\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u0427\u0430\u0441\u0442\u044c 2<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 Java \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 pattern-matching, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 FP \u044f\u0437\u044b\u043a\u0430\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"primer-na-drugih-yazykah\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445<\/h2>\n<p>  <\/p>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0412 Kotlin \u0438 Rust \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 Result, \u0432 Scala \u0438 Haskell \u2014 Try. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 pattern-matching \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <\/p>\n<p>Scala<\/p>\n<p>  <\/p>\n<pre><code class=\"scala\">val result = divideWithTry(10, 0) match { \u00a0 case Success(i) => i \u00a0 case Failure(DivideByZero()) => None }<\/code><\/pre>\n<p>  <\/p>\n<p>Rust<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    let greeting_file_result = File::open(\"hello.txt\");     let greeting_file = match greeting_file_result {         Ok(file) => file,         Err(error) => panic!(\"Problem opening the file: {:?}\", error),     };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 pattern-matching \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c (idiomatic) \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u0410 \u043a\u0430\u043a \u0434\u0435\u043b\u043e \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u0432 Java?<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"nemnogo-predystorii\">\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0432 Java \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 3-\u044f \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f. \u041f\u0435\u0440\u0432\u0430\u044f \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0432 Java 5, \u0432\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u2014 \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043b\u044f\u043c\u0431\u0434 \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0430 Java 8. \u041d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u044f\u0437\u044b\u043a Java \u0441\u0434\u0435\u043b\u0430\u0432 \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u044d\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0438 \u043e\u0434\u043d\u043e\u043c\u043e\u043c\u0435\u043d\u0442\u043d\u043e \u0441 \u0432\u044b\u0445\u043e\u0434\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Java. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043b\u0435 8-\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Java release-train \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f, \u043d\u043e\u0432\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0441\u0442\u0430\u043b\u0438 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0447\u0430\u0449\u0435, \u043d\u043e \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0447\u0438 \u0441\u0442\u0430\u043b\u0438 \u043d\u0435 \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0440\u0443\u043f\u043d\u044b\u043c\u0438. \u0412\u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0433\u043e\u0434\u044b, \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0438\u043c\u0435\u044e\u0442 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e pre-view, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0444\u0438\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440.<\/p>\n<p>  <\/p>\n<ul>\n<li>JEP 305: Pattern Matching for instanceof \u2014 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0441\u0430\u0445\u0430\u0440, \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e;<\/li>\n<li>JEP 359: Records \u2014 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u0430\u043a \u0437\u0430\u043c\u0435\u043d\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (tuples);<\/li>\n<li>JEP 360: Sealed Classes \u2014 \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u0432 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435;<\/li>\n<li>JEP 405: Record Patterns \u2014 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u0435-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438, \u0437\u0430\u0447\u0435\u043c?<\/li>\n<li>JEP 406: Pattern Matching for switch \u2014 \u0443\u0436\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 preview, \u0435\u0449\u0435 \u043d\u0435 \u0444\u0438\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u043d\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u044d\u0442\u0438 \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438 \u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u043e\u0441\u043e\u0431\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u043c\u0438, \u043d\u043e \u0432\u0437\u044f\u0442\u044b\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u0438\u0445\u043e \u0438\u0434\u0443\u0449\u0435\u0439 3-\u0435\u0439 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u0438 \u0432 Java \u2014 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"modelirovanie-rezultata-s-isklyucheniem\">\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0435\u0431\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0442\u0438\u043f\u0430 <code>T<\/code> \u0438\u043b\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0417\u043d\u0430\u043a\u043e\u043c\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f?<\/p>\n<p>  <\/p>\n<p>\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u043e\u0433\u043e (sealed) \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>Result&lt;T><\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public sealed interface Result&lt;T> permits Success, Failure { ... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0443\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432 \u2014 <code>Success<\/code> \u0438 <code>Failure<\/code>. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f switch \u043c\u043e\u0436\u0435\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u043d\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043d\u0430\u0431\u043e\u0440 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 (records)<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public record Success&lt;T>(T value) implements Result&lt;T> { }  public record Failure&lt;T>(Exception exception) implements Result&lt;T> { }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u043d\u043e\u0441\u0438\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (ADT).<\/p>\n<p>  <\/p>\n<h2 id=\"poluchenie-rezultata\">\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0449\u0443\u044e (factory) \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    static &lt;T> Result&lt;T> runCatching(CheckedSupplier&lt;T> suppl) {         try {             return new Success&lt;>(suppl.get());         } catch (Exception e) {             return new Failure&lt;>(e);         }     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c URL \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438, \u0437\u0434\u0435\u0441\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 URL \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c MalformedURLException. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    @Test public void testUrl() {         var urlResult = Result.runCatching(() -> new URL(\"foo\/bar\"));         assertTrue(urlResult instanceof Failure);         urlResult.onFailure(e -> assertTrue(e instanceof MalformedURLException));     }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"obrabotka-rezultata\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430<\/h2>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0430 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f URL. \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 URL, \u0438\u043b\u0438 URL \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0438\u043c\u0435\u0442\u044c \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430 \u0438 \u0442\u043e\u0433\u0434\u0430 <code>getPort()<\/code> \u0432\u0435\u0440\u043d\u0435\u0442 -1.<\/p>\n<p>  <\/p>\n<h3 id=\"1-tradicionnyy-kod\">1. \u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Optional&lt;Integer> getURLPortTraditional(String urlStr) {         try {             URL url = new URL(urlStr);             int port = url.getPort();             return port == -1 ? Optional.empty() : Optional.of(port);         } catch (MalformedURLException e) {             return Optional.empty();         }     }    <\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u0435\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<p>  <\/p>\n<h3 id=\"2-sopostavlenie-s-obrazcom-klassa\">2. \u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Optional&lt;Integer> getURLPortWithSimplePatternMatching(String url) {         var portResult = runCatching(() -> new URL(url)).map(URL::getPort);         return switch (portResult) {         case Success&lt;Integer> s -> s.value() == -1 ? Optional.empty() : Optional.of(s.value());         case Failure f -> Optional.empty();         };     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c c \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 <code>Success&lt;Integer> s<\/code>, \u043f\u043e\u0440\u0442 \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u044f\u0432\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <code>s.value()<\/code><\/p>\n<p>  <\/p>\n<h3 id=\"3-sopostavlenie-s-obrazcom-zapisi-s-dekonstrukciey-zapisi-na-komponenty\">3. \u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0434\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Optional&lt;Integer> getURLPortWithRecordMatching(String url) {         var portResult = runCatching(() -> new URL(url)).map(URL::getPort);         return switch (portResult) {         case Success&lt;Integer>(Integer port) -> port == -1 ? Optional.empty() : Optional.of(port);         case Failure f -> Optional.empty();         };     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e <code>Success&lt;Integer>(Integer port)<\/code>, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>port<\/code> \u0438 \u043d\u0435\u044f\u0432\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u0437\u0430\u043f\u0438\u0441\u0438. \u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u0435-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 (record deconstruction) \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<h3 id=\"4-sopostavlenie-s-obrazcom-zapisi-s-vyvodom-tipa\">4. \u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0442\u0438\u043f\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Optional&lt;Integer> getURLPortWithRecordMatchingInfere(String url) {         var portResult = runCatching(() -> new URL(url)).map(URL::getPort);         return switch (portResult) {         case Success&lt;Integer>(var port) -> port == -1 ? Optional.empty() : Optional.of(port);         case Failure f -> Optional.empty();         };     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 3, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>var port<\/code>, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0430\u043c \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<p>  <\/p>\n<h3 id=\"5-kak-budet-v-okonchatelnoy-versii-java-20\">5. \u041a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Java 20+<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Optional&lt;Integer> getURLPortWithRecordMatchingInfere(String url) {         var portResult = runCatching(() -> new URL(url)).map(URL::getPort);         return switch (portResult) {         case Success(var port) -> port == -1 ? Optional.empty() : Optional.of(port);         case Failure f -> Optional.empty();         };     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0430\u044f \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043e\u0434, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441 \u0437\u0430\u043f\u0438\u0441\u044c\u044e <code>Success(var port)<\/code>, \u0442\u0438\u043f\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e \u0432\u043e\u043e\u0431\u0449\u0435, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u044d\u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u0430\u043c. \u041a\u0440\u0430\u0441\u043e\u0442\u0430.<\/p>\n<p>  <\/p>\n<h3 id=\"6-bez-sopostavleniya-s-obrazcom\">6. \u0411\u0435\u0437 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Optional&lt;Integer> getURLPortWithMonad(String url) {         return runCatching(() -> new URL(url)).map(URL::getPort)             .filter(port -> port != -1)             .fold(port -> Optional.of(port), exception -> Optional.empty());     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 pattern-matching-\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"kombinirovanie-rezultatov\">\u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/h2>\n<p>  <\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u0432\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 <code>Result&lt;Integer><\/code> \u0438 \u043d\u0430\u0439\u0434\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0435\u0441\u043b\u0438 \u043e\u0431\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"7-naivnoe-kombinirovanie-s-raspakovkoy-result\">7. \u041d\u0430\u0438\u0432\u043d\u043e\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u043e\u0439 Result<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Result&lt;Integer> sumResultsNaive(Result&lt;Integer> i1, Result&lt;Integer> i2) {         if (i1.isSuccess() &amp;&amp; i2.isSuccess()) {             Integer x1 = i1.getOrNull();             Integer x2 = i2.getOrNull();             return Success.of(sum(x1, x2));         }          return i1.isFailure() ? i1 : i2;     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u043d\u0430\u043f\u0438\u0448\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0441 \u043f\u0440\u0438\u0435\u043c\u0430\u043c\u0438 FP, \u043d\u043e \u044d\u0442\u043e \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<p>  <\/p>\n<h3 id=\"8-kombinirovanie-v-stile-fp-pri-pomoschi-vlozhennyh-nested-flatmap\">8. \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u0442\u0438\u043b\u0435 FP \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 (nested) <code>flatMap<\/code><\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">    Result&lt;Integer> sumResultsFlatMap(Result&lt;Integer> i1, Result&lt;Integer> i2) {         return i1.flatMap(x1 -> i2.map(x2 -> sum(x1, x2)));     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u0438\u0434\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u0435\u043c FP \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437\u0443\u0447\u0438\u0442\u044c, \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u041a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443 \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043d\u0430\u0434\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<p>  <\/p>\n<h3 id=\"9-kombinirovanie-s-primeneniem-pattern-matching\">9. \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c pattern matching.<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u043d\u0430\u0434\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Result&lt;Integer><\/code> \u0438 <code>Option&lt;Integer><\/code>, \u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043b\u0438\u0431\u043e \u043d\u0430\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 #7, \u043b\u0438\u0431\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f\u044b \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c #8, \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 pattern matching.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    Result&lt;Integer> sumResultsFromDifferentMonads(Option&lt;Integer> i1, Result&lt;Integer> i2) {         record TwoInts(Option&lt;Integer> i1, Result&lt;Integer> i2) {};         return switch (new TwoInts(i1,i2)) {         case TwoInts(Some&lt;Integer>(var x1), Success&lt;Integer>(var x2)) -> Success.of(sum(x1, x2));         default -> i2.isFailure() ? i2 : Failure.of(new NoSuchElementException());          };     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e (!) \u0437\u0430\u043f\u0438\u0441\u044c <code>TwoInts<\/code>, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0435\u0451 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438 \u044d\u0442\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 Scala \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a. <\/p>\n<p>  <\/p>\n<pre><code class=\"scala\">    def sumScala(i1: Option[Int], i2: Try[Int]) : Option[Int] = {       (i1, i2) match {         case (Some(x1), Success(x2)) => Some(x1 + x2)         case (_, Failure(f)) => i2         case (None, _) => None()         }     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 Scala \u043f\u043e\u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0447\u0435\u043c \u0432 Java, \u043d\u043e \u0438\u0434\u0435\u044f \u0442\u0430 \u0436\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0438 <code>TwoInts<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u044b\u0439 \u043a\u043e\u0440\u0442\u0435\u0436 <code>(i1, i2)<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b <code>\"_\"<\/code> \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0441 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0442\u043e \u0435\u0441\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. Java \u043f\u043e\u043a\u0430 \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u041c\u043d\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 Kotlin. \u0423\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438, \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 FP \u044f\u0437\u044b\u043a\u0438. \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u044f\u0437\u044b\u043a\u0435 (Kotlin, Haskell, Rust, \u0434\u0440.) \u0411\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 Java.<\/p>\n<p>  <\/p>\n<h2 id=\"problemy\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h2>\n<p>  <\/p>\n<p>JEP 406 \u0435\u0449\u0435 \u043d\u0435 \u0444\u0438\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 4-\u043e\u0439 \u0441\u0442\u0430\u0434\u0438\u0438 preview \u0432 Java 20, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 (\u0444\u0435\u0432\u0440\u0430\u043b\u044c 2023) \u0435\u0449\u0435 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0432\u044b\u0448\u043b\u0430. \u0410\u0432\u0442\u043e\u0440 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 Java 19 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 Eclipse Version: 2023-03 M2 (4.27.0 M2).<\/p>\n<p>  <\/p>\n<ul>\n<li>Eclipse \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 4, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 port<\/li>\n<li>JDK 19 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 3 \u0438 4, \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0447\u0442\u043e switch \u043d\u0435 \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0430 <a href=\"https:\/\/stackoverflow.com\/questions\/73787918\/java-19-compiler-issues-when-trying-record-patterns-in-switch-expressions\" rel=\"nofollow noopener noreferrer\">https:\/\/stackoverflow.com\/questions\/73787918\/java-19-compiler-issues-when-trying-record-patterns-in-switch-expressions<\/a>, \u043b\u0435\u0447\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c default \u043a\u0435\u0439\u0441\u0430. <\/p>\n<p>  <\/p>\n<p>\u0424\u0438\u0447\u0438 \u0435\u0449\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 preview, \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u0432 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Java 20 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e.<\/p>\n<p>  <\/p>\n<h2 id=\"implementaciya-result\">\u0418\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Result<\/h2>\n<p>  <\/p>\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c Kotlin Result \u043a\u0430\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437\u0435\u0446 API \u0438 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0435\u0433\u043e \u0432 Java. \u0421 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/skopylov58\/java-kotlin-result\" rel=\"nofollow noopener noreferrer\">GitHub<\/a>. \u041f\u043e\u0447\u0435\u043c\u0443 Kotlin? \u0412\u043e \u043f\u0435\u0440\u0432\u044b\u0445, \u0443 Kotlin \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0432\u043e \u0432\u0442\u043e\u0440\u044b\u0445 \u2014 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 API. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0441\u0435\u043f\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/li>\n<li>\u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 Java Optional \u0438 Stream<\/li>\n<li>AutoCloseable result<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"vyvody\">\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0433\u043e\u0434\u044b \u0432 Java \u0438\u0434\u0435\u0442 \u0442\u0438\u0445\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u044f<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0421 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u0445 (sealed) \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 (records) \u0441\u0442\u0430\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u043a\u0430\u043a \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (ADT).<\/li>\n<li>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (records pattern matching) \u0441 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432 Java.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e Java \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u0447\u0438\u0441\u0442\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043e\u0433\u0430\u0442\u044f\u0442 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 Java.<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044f \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u0440\u0435\u043d \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 FP, \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Java \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435\u0442 \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u043a\u0430\u043a Result, Either, Option \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 (\u043a\u0441\u0442\u0430\u0442\u0438\u0442 <code>java.util.Optional<\/code> \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0438 \u043d\u0435 \u043f\u043e\u0434\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u0440\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c). \u0421 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043d\u0438\u0435\u043c \u0436\u0434\u0443 \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u0430\u043c\u0438 pattern-matching \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/skopylov58\/java-kotlin-result\" rel=\"nofollow noopener noreferrer\">GitHub<\/a><\/p>\n<p>  <\/p>\n<p>\u0421 \u0443\u0432\u0430\u0436\u0435\u043d\u0438\u0435\u043c<br \/>  \u0421\u0435\u0440\u0433\u0435\u0439 \u041a\u043e\u043f\u044b\u043b\u043e\u0432<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/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\/post\/721326\/\"> https:\/\/habr.com\/ru\/post\/721326\/<\/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 article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h1 id=\"obrabotka-isklyucheniy-v-java-s-ispolzovaniem-sopostavleniya-s-obrazcom-pattern-matching\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (pattern matching).<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u0442\u0435\u0439 <\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/676852\/\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435<\/a> \u0438 <\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/687954\/\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Java \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u0427\u0430\u0441\u0442\u044c 2<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 Java \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 pattern-matching, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 FP \u044f\u0437\u044b\u043a\u0430\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"primer-na-drugih-yazykah\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445<\/h2>\n<p>  <\/p>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0412 Kotlin \u0438 Rust \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 Result, \u0432 Scala \u0438 Haskell \u2014 Try. \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 pattern-matching \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <\/p>\n<p>Scala<\/p>\n<p>  <\/p>\n<pre><code class=\"scala\">val result = divideWithTry(10, 0) match { \u00a0 case Success(i) => i \u00a0 case Failure(DivideByZero()) => None }<\/code><\/pre>\n<p>  <\/p>\n<p>Rust<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    let greeting_file_result = File::open(\"hello.txt\");     let greeting_file = match greeting_file_result {         Ok(file) => file,         Err(error) => panic!(\"Problem opening the file: {:?}\", error),     };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 pattern-matching \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c (idiomatic) \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u0410 \u043a\u0430\u043a \u0434\u0435\u043b\u043e \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u0432 Java?<\/p>\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-346522","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346522","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=346522"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346522\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=346522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=346522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=346522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}