{"id":9287,"date":"2021-05-30T15:34:45","date_gmt":"2021-05-30T15:34:45","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=9287"},"modified":"2024-04-13T13:11:03","modified_gmt":"2024-04-13T13:11:03","slug":"scala-reduce-right-scala-tutorial-reduceright-function-example","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/","title":{"rendered":"Scala &#8211; Reduce Right"},"content":{"rendered":"\r\n<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Scala Tutorial - ReduceRight Function Example&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:6145,&quot;3&quot;:{&quot;1&quot;:0,&quot;3&quot;:1},&quot;14&quot;:{&quot;1&quot;:3,&quot;3&quot;:1},&quot;15&quot;:&quot;Arial&quot;}\">Scala Tutorial ReduceRight Function Example<\/span><\/h2>\r\n<p>&nbsp;<\/p>\r\n<p>The <strong>reduceRight <\/strong>is relevant to both<a href=\"https:\/\/prwatech.in\/blog\/scala\/scala-a-quick-overview\/\"> Scala&#8217;s<\/a> Mutable and <a href=\"http:\/\/scala-lang.org\">Immutable <\/a>assortment information structures.<\/p>\r\n\r\n\r\n\r\n<p>The reduceRight technique takes an affiliated twofold administrator work as boundary and will utilize it to implode components from the assortment. The request for crossing the components in the assortment is from option to left and henceforth the name reduceRight. In contrast to the foldRight technique, reduceRight doesn&#8217;t permit you to likewise determine an underlying worth.<\/p>\r\n<p>The <code>reduceLeft<\/code> function in Scala is a higher-order function used to iteratively combine elements of a collection from left to right using a binary operation. It applies the binary operator to the elements of the collection starting from the leftmost element and accumulates a result until all elements are process .Scala Tutorial ReduceRight Function Example<\/p>\r\n<p>In this example, the binary operator <code>(acc, elem) =&gt; acc * elem<\/code> is applies iteratively to compute the product of all elements in the list starting from the leftmost element.<\/p>\r\n<p>Understanding how to use <code>reduceLeft<\/code> is important for functional programming in Scala,and as it allows for elegant and in a concise solutions to aggregation tasks. By leveraging <code>reduceLeft<\/code>, developers can perform complex computations on collections while adhering to functional programming principles.<\/p>\r\n\r\n\r\n\r\n<h3><strong>use case 1:<\/strong><\/h3>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>find the sum of the elements using reduceRight function\r\n\r\nscala&gt; val donutPrices: Seq[Double] = Seq(4.5, 2.0, 2.5)\r\nscala&gt; println(s\"Elements of donutPrices = $donutPrices\")\r\nscala&gt; val sum: Double = donutPrices.reduceRight(_ + _)\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"499\" height=\"140\" class=\"wp-image-9288\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png 499w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572-300x84.png 300w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>2use case 2:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>Find the cheapest donut using reduceRight function\r\n\r\nWe can also use the reduceRight method to find the minimum element in the Sequence of donut prices as shown below.\r\n\r\nscala&gt; val donutPrices: Seq[Double] = Seq(4.5, 2.0, 2.5)\r\nscala&gt; println(s\"Elements of donutPrices = $donutPrices\")\r\nscala&gt; println(s\"Cheapest donut price = ${donutPrices.reduceRight(_ min_)}\")\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"133\" class=\"wp-image-9289\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-573.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-573.png 606w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-573-300x66.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>use case 3:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>Find the most expensive donut using reduceRight function\r\nwe can use the reduceRight method to find the maximum element in the Sequence of donut prices.\r\n\r\nscala&gt; val donutPrices: Seq[Double] = Seq(1.5, 2.0, 2.5)\r\nscala&gt; println(s\"Elements of donutPrices = $donutPrices\")\r\nscala&gt; println(s\"Cheapest donut price = ${donutPrices.reduceRight(_ max _)}\")\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"144\" class=\"wp-image-9290\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-574.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-574.png 606w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-574-300x71.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>Scala Tutorial ReduceRight Function Example &nbsp; The reduceRight is relevant to both Scala&#8217;s Mutable and Immutable assortment information structures. The reduceRight technique takes an affiliated twofold administrator work as boundary and will utilize it to implode components from the assortment. The request for crossing the components in the assortment is from option to left and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,1698],"tags":[1504,1498,1507,1499,1506,1500,1501,1502,1503,1508],"class_list":["post-9287","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-how-reduce-right-function-is-used-in-scala","tag-reduce-right","tag-reduce-right-examples","tag-reduce-right-scala","tag-reduce-right-usecases","tag-scala-reduce-right","tag-scala-reduce-right-function","tag-scala-reduce-right-method","tag-what-is-reduce-right-function","tag-what-is-scala-reduce-right"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scala Tutorial ReduceRight Function Example - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Scala Tutorial ReduceRight Function Example - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Tutorial ReduceRight Function Example - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Scala Tutorial ReduceRight Function Example - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-30T15:34:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-13T13:11:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/\",\"name\":\"Scala Tutorial ReduceRight Function Example - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png\",\"datePublished\":\"2021-05-30T15:34:45+00:00\",\"dateModified\":\"2024-04-13T13:11:03+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Scala Tutorial ReduceRight Function Example - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png\",\"width\":499,\"height\":140},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Reduce Right\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Tutorial ReduceRight Function Example - Prwatech","description":"Master Scala Tutorial ReduceRight Function Example - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Scala Tutorial ReduceRight Function Example - Prwatech","og_description":"Master Scala Tutorial ReduceRight Function Example - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2021-05-30T15:34:45+00:00","article_modified_time":"2024-04-13T13:11:03+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png","type":"","width":"","height":""}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/","name":"Scala Tutorial ReduceRight Function Example - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png","datePublished":"2021-05-30T15:34:45+00:00","dateModified":"2024-04-13T13:11:03+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Scala Tutorial ReduceRight Function Example - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-572.png","width":499,"height":140},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-reduce-right-scala-tutorial-reduceright-function-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Reduce Right"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=9287"}],"version-history":[{"count":5,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9287\/revisions"}],"predecessor-version":[{"id":11475,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9287\/revisions\/11475"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=9287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=9287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=9287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}