F# Array Library - Array.Blit

Description:
The blit function allows you to read a range from one array, into a second array.

Arguments:
1.) ‘a array – The source array.
2.) int – The index of the source array to begin your copy.
3.) ‘a array – The destination array.
4.) int – The index of the destination array to begin your copy.
5.) int – The number of elements to copy over.

Return Value:
unit

Example:
We start with a source array and destination array and then copy two of the elements from the first array into the second array. See the image below:




Here’s the actual source code of how we’d do this with the Array.Blit function:

let sourceArray = [| 'a' ; 'b' ; 'c' |];;
let destinationArray = [| 'd' ; 'e' ; 'f' |];;
Array.blit sourceArray 0 destinationArray 1 2;;

It should also be noted that further memory will not be allocated for the destinationArray to handle the new elements. If it’s not large enough an IndexOutOfRangeException will be thrown.

Leave Us a Comment!
Title (we need it)

Your Name (we need it)

Your Comment (we need it)