@@ -9,23 +9,53 @@ module Array =
99 open System
1010 open FSharp.Core .CompilerServices
1111 open FSharpPlus.Internals .Errors
12+ #if NET45 // from FSharp.Core
13+ let insertAt ( index : int ) ( value : 'T ) ( source : 'T array ) : 'T array =
14+
15+ if index < 0 || index > source.Length then
16+ invalidArg " index" " index must be within bounds of the array"
17+
18+ let length = source.Length + 1
19+ let result : 'T array = Array.zeroCreate( length)
20+
21+ if index > 0 then
22+ Array.Copy( source, result, index)
23+
24+ result[ index] <- value
25+
26+ if source.Length - index > 0 then
27+ Array.Copy( source, index, result, index + 1 , source.Length - index)
28+
29+ result
30+ #endif
1231
1332 /// <summary>Adds an element to the beginning of the given array</summary>
1433 /// <param name="value">The element to add</param>
1534 /// <param name="array">The array to add to</param>
1635 /// <returns>A new array with the element added to the beginning.</returns>
1736 let cons value array =
37+ #if ! NET45
1838 raiseIfNull ( nameof( array)) array
1939 Array.insertAt 0 value array
40+ #else
41+ raiseIfNull " array" array
42+ insertAt 0 value array
43+ #endif
2044
2145 /// <summary>Splits the array in head and tail.</summary>
2246 /// <param name="array">The input array.</param>
2347 /// <returns>A tuple with the head and the tail of the original array.</returns>
2448 /// <exception cref="T:System.ArgumentException">Thrown when the input array is empty.</exception>
2549 let uncons array =
50+ #if ! NET45
2651 raiseIfNull ( nameof( array)) array
2752 if Array.isEmpty array then invalidArg ( nameof( array)) LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
2853 else array[ 0 ], array[ 1 ..]
54+ #else
55+ raiseIfNull " array" array
56+ if Array.isEmpty array then invalidArg " array" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
57+ else array[ 0 ], array[ 1 ..]
58+ #endif
2959
3060 /// <summary>Applies an array of functions to an array of values and concatenates them.</summary>
3161 /// <param name="f">The array of functions.</param>
0 commit comments