{"id":2811,"date":"2015-01-25T20:46:25","date_gmt":"2015-01-25T20:46:25","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=2811"},"modified":"2015-01-25T20:46:25","modified_gmt":"2015-01-25T20:46:25","slug":"f-array-slicing","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/f-array-slicing\/","title":{"rendered":"F# Array Slicing"},"content":{"rendered":"<p>This should be a short post regarding something I hadn&#8217;t seen before &#8211; F#&#8217;s array slicing syntax. One of the problems of coming to F# from another language is that sometimes you just use language features without realising that the new language offers more options &#8211; this is one such feature of arrays in F#.<\/p>\n<p>An array slice is really just a way of creating an array made up of a subset of another array. So for example let&#8217;s assume we have the following<\/p>\n<pre class=\"brush: fsharp; title: ; notranslate\" title=\"\">\r\nlet array = &#x5B;| 1; 2; 3; 4; 5; 6 |]\r\n<\/pre>\n<p>We can access the array via an indexer, but as you probably know, you access the indexer using dot notation, for example<\/p>\n<pre class=\"brush: fsharp; title: ; notranslate\" title=\"\">\r\nlet v = array.&#x5B;3]\r\n<\/pre>\n<p>But we can do more than just get a single item, we use the same basic syntax to get slices of the array, for example<\/p>\n<pre class=\"brush: fsharp; title: ; notranslate\" title=\"\">\r\n\/\/ create a new array of items 2 to 4 inclusive\r\nlet a = array.&#x5B;2..4]\r\n\r\n\/\/ create a new array of items up to and including item 3 (i.e. 0..3)\r\nlet b = array.&#x5B;..3]\r\n\r\n\/\/ create a new array of items from item 3 until the end of the array\r\nlet c = array.&#x5B;3..]\r\n\r\n\/\/ create a clone of all elements\r\nlet d = array.&#x5B;*]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This should be a short post regarding something I hadn&#8217;t seen before &#8211; F#&#8217;s array slicing syntax. One of the problems of coming to F# from another language is that sometimes you just use language features without realising that the new language offers more options &#8211; this is one such feature of arrays in F#. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-2811","post","type-post","status-publish","format-standard","hentry","category-f"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=2811"}],"version-history":[{"count":1,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2811\/revisions"}],"predecessor-version":[{"id":2812,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2811\/revisions\/2812"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=2811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=2811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=2811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}