{"id":2568,"date":"2015-09-11T02:43:23","date_gmt":"2015-09-11T02:43:23","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=2568"},"modified":"2015-09-11T02:43:23","modified_gmt":"2015-09-11T02:43:23","slug":"scala-zip-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/scala-zip-example\/","title":{"rendered":"Scala Zip Example"},"content":{"rendered":"<p>The zip function combines two lists into tuples. If the lists are of differing lengths, the shorter length is used. If you don&#8217;t like this behavior, the zipAll function will keep all elements, filling in specified values for the blanks (compare this to the recycling rule in R, which lets you continuously cycle through the shorter list).<\/p>\n<pre lang=\"Scala\">\nval arr1 = List(\"a\", \"b\", \"c\")\nval arr2 = List(1, 2, 3)\n\narr1.zip(arr2)\n<\/pre>\n<p>The result is tuples of each:<\/p>\n<pre lang=\"Scala\">\nres2: List[(String, Int)] = List((a,1), (b,2), (c,3))\n<\/pre>\n<p>If you make a longer array, you get tuples with a length at the shortest of the two:<\/p>\n<pre lang=\"scala\">\nvar arr3 = List(4, 5, 6, 7)\narr1.zip(arr3)\n<\/pre>\n<pre>\nres3: List[(String, Int)] = List((a,4), (b,5), (c,6))\n<\/pre>\n<p>This also applies if you use a shorter array:<\/p>\n<pre lang=\"Scala\">\nvar arr4 = List(4, 5)\narr1.zip(arr4)\n<\/pre>\n<p>Result:<\/p>\n<pre>\nres5: List[(String, Int)] = List((a,4), (b,5))\n<\/pre>\n<p>If you don&#8217;t like this behavior, consider using <a href=\"http:\/\/www.garysieling.com\/blog\/scala-zipall-example\">zipAll<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The zip function combines two lists into tuples. If the lists are of differing lengths, the shorter length is used. If you don&#8217;t like this behavior, the zipAll function will keep all elements, filling in specified values for the blanks (compare this to the recycling rule in R, which lets you continuously cycle through the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/scala-zip-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Scala Zip 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,488],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2568"}],"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=2568"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2568\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=2568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=2568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=2568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}