{"id":3117,"date":"2016-02-09T03:47:09","date_gmt":"2016-02-09T03:47:09","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3117"},"modified":"2016-02-09T03:47:09","modified_gmt":"2016-02-09T03:47:09","slug":"scala-fill-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/scala-fill-example\/","title":{"rendered":"Scala fill example"},"content":{"rendered":"<p>&#8220;Fill&#8221; is a static collection method, as one of several ways to instantiate a static list.<\/p>\n<p>If you want a list of several values, you could do something like this:<\/p>\n<pre lang=\"scala\">\nval x = List(0, 0, 0, 0, 0)\n<\/pre>\n<p>But, fill makes this easier:<\/p>\n<pre lang=\"scala\">\nscala> List.fill(0)(5)\nres22: List[Int] = List(0, 0, 0, 0, 0)\n<\/pre>\n<p>You can pass anything into this:<\/p>\n<pre lang=\"scala\">\nscala> List.fill(5)(\"test\")\nres21: List[String] = List(test, test, test, test, test)\n<\/pre>\n<p>You can even make multi-dimensional arrays this way:<\/p>\n<pre lang=\"scala\">\nscala> List.fill(2, 3)(0)\nres26: List[List[Int]] = List(List(0, 0, 0), List(0, 0, 0))\n\nscala> List.fill(2, 3, 4)(0)\nres27: List[List[List[Int]]] = \n  List(\n    List(\n      List(0, 0, 0, 0), \n      List(0, 0, 0, 0), \n      List(0, 0, 0, 0)), \n    List(List(0, 0, 0, 0),\n         List(0, 0, 0, 0), \n         List(0, 0, 0, 0)))\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;Fill&#8221; is a static collection method, as one of several ways to instantiate a static list. If you want a list of several values, you could do something like this: val x = List(0, 0, 0, 0, 0) But, fill makes this easier: scala> List.fill(0)(5) res22: List[Int] = List(0, 0, 0, 0, 0) You can &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/scala-fill-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Scala fill example&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[480,482,485],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3117"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3117"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3117\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}