{"id":8630,"date":"2021-05-24T15:21:44","date_gmt":"2021-05-24T15:21:44","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=8630"},"modified":"2024-04-13T11:12:10","modified_gmt":"2024-04-13T11:12:10","slug":"scala-placeholder-syntax","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/","title":{"rendered":"Scala &#8211; Placeholder Syntax"},"content":{"rendered":"\r\n<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;How to use placeholder syntax in scala Archives&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;}\">How to use placeholder syntax in scala<\/span><\/h2>\r\n<p>&nbsp;<\/p>\r\n<p>The requirement for making <a href=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-high-order-functions\/\">everything<\/a> brief lead Scala to raise <a href=\"http:\/\/scala-lang.org\">something<\/a> many refer to as the Placeholder sentence structure. Scala permits the utilization of <strong>underscore<\/strong> (meant as &#8216;_&#8217;) to be utilized as placeholders for at least one boundaries. we can consider the underscore to something that should be filled in with a worth.<\/p>\r\n<p>In Scala, the placeholder syntax is a concise way to define anonymous functions, especially useful when passing functions as arguments to higher-order functions like <code>map<\/code>, <code>filter<\/code>, or <code>reduce<\/code>. Placeholder syntax allows developers to write compact and readable code by omitting explicit function parameters and using underscores (<code>_<\/code>) to represent placeholders for parameters.<\/p>\r\n<p>For example, when using <code>map<\/code> on a collection, instead of explicitly defining a named function with a single parameter, you can use placeholder syntax like <code>collection.map(_ * 2)<\/code> to double each element of the collection. Here, <code>_<\/code> represents the parameter passed to the anonymous function.<\/p>\r\n<p>Placeholder syntax is particularly handy for simple, one-line transformations where the function logic is concise and easily understood. It promotes functional programming principles by emphasizing the behavior of functions rather than their specific parameter names.<\/p>\r\n<p>When using placeholder syntax, it&#8217;s important to note that each underscore (<code>_<\/code>) represents a different parameter position in the function. For multiple parameters, you can use consecutive underscores (<code>_ + _<\/code>) to represent each parameter sequentially.<\/p>\r\n\r\n\r\n\r\n<h4><strong>Use case 1:<\/strong><\/h4>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>scala&gt; val somenumbers= List(1,2,3,4,5)\r\nscala&gt;  somenumbers.foreach(println _)\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=\"434\" height=\"158\" class=\"wp-image-8631\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png 434w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50-300x109.png 300w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/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>Suppose we want to check if the number is greater than 5.\r\nscala&gt; val somenumbers= List(3,4,5,8,10,9)\r\nscala&gt; somenumbers.filter(_ &gt; 5)\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=\"456\" height=\"99\" class=\"wp-image-8632\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-51.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-51.png 456w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-51-300x65.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/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>Suppose we want to add two numbers.\r\nscala&gt; val f = (_: Int) + (_: Int)\r\nscala&gt; f(15, 10)\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=\"591\" height=\"114\" class=\"wp-image-8633\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-52.png\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-52.png 591w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-52-300x58.png 300w\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" \/><\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>How to use placeholder syntax in scala &nbsp; The requirement for making everything brief lead Scala to raise something many refer to as the Placeholder sentence structure. Scala permits the utilization of underscore (meant as &#8216;_&#8217;) to be utilized as placeholders for at least one boundaries. we can consider the underscore to something that should [&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":[1368,1370,1373,1371,1374,1364,1369,1372,1375,1365],"class_list":["post-8630","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-define-placeholder-in-scala","tag-how-placeholder-used-in-scala","tag-how-to-use-placeholder-syntax-in-scala","tag-placeholder-in-scala","tag-placeholder-syntax","tag-scala-placeholder","tag-scala-placeholder-definition","tag-scala-placeholder-examples","tag-what-is-placeholder-in-scala","tag-what-is-placeholder-syntax-in-scala"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use placeholder syntax in scala - Prwatech<\/title>\n<meta name=\"description\" content=\"Master How to Use Placeholder Syntax in Scala - 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=\"How to use placeholder syntax in scala - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master How to Use Placeholder Syntax in Scala - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/\" \/>\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-24T15:21:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-13T11:12:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.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-placeholder-syntax\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/\",\"name\":\"How to use placeholder syntax in scala - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png\",\"datePublished\":\"2021-05-24T15:21:44+00:00\",\"dateModified\":\"2024-04-13T11:12:10+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master How to Use Placeholder Syntax in Scala - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png\",\"width\":434,\"height\":158},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Placeholder Syntax\"}]},{\"@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":"How to use placeholder syntax in scala - Prwatech","description":"Master How to Use Placeholder Syntax in Scala - 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":"How to use placeholder syntax in scala - Prwatech","og_description":"Master How to Use Placeholder Syntax in Scala - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2021-05-24T15:21:44+00:00","article_modified_time":"2024-04-13T11:12:10+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.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-placeholder-syntax\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/","name":"How to use placeholder syntax in scala - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png","datePublished":"2021-05-24T15:21:44+00:00","dateModified":"2024-04-13T11:12:10+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master How to Use Placeholder Syntax in Scala - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/05\/image-50.png","width":434,"height":158},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-placeholder-syntax\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Placeholder Syntax"}]},{"@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\/8630","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=8630"}],"version-history":[{"count":4,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8630\/revisions"}],"predecessor-version":[{"id":11457,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8630\/revisions\/11457"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=8630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=8630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=8630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}