Skip to content

Commit 5fafab0

Browse files
gustywallymathieu
authored andcommitted
Fix several functions in ResizeArray
1 parent 34ab1bc commit 5fafab0

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/FSharpPlus/Extensions/ResizeArray.fs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ module ResizeArray =
2626
/// <summary>Applies the given function to each element of the collection.</summary>
2727
/// <param name="action">The function to apply to elements from the input ResizeArray.</param>
2828
/// <param name="source">The input ResizeArray.</param>
29-
let iter (action: 'T -> 'U) (source: ResizeArray<'T>) =
29+
let iter (action: 'T -> unit) (source: ResizeArray<'T>) : unit =
3030
#if !NET45
3131
raiseIfNull (nameof source) source
3232
#endif
3333

34-
ResizeArray (Seq.map action source)
34+
Seq.iter action source
3535

3636
/// <summary>Applies a ResizeArray of functions to a ResizeArray of values and concatenates them.</summary>
3737
/// <param name="f">The functions.</param>
@@ -95,20 +95,20 @@ module ResizeArray =
9595
source |> Array.toSeq |> Seq.intersperse element |> Seq.toArray : 'T []
9696

9797
/// Creates a sequence of arrays by splitting the source array on any of the given separators.
98-
let split (separators: seq<_ []>) (source: _ []) =
98+
let split (separators: seq<ResizeArray<'T>>) (source: ResizeArray<'T>) : seq<ResizeArray<'T>> =
9999
#if !NET45
100100
raiseIfNull (nameof separators) separators
101101
raiseIfNull (nameof source) source
102102
#endif
103-
source |> Array.toSeq |> Seq.split separators |> Seq.map Seq.toArray
103+
source |> Seq.split separators |> Seq.map ResizeArray
104104

105105
/// Replaces a subsequence of the source array with the given replacement array.
106-
let replace (oldValue: _ []) (newValue: _ []) source =
106+
let replace (oldValue: ResizeArray<'T>) (newValue: ResizeArray<'T>) (source: ResizeArray<'T>) : ResizeArray<'T> =
107107
#if !NET45
108108
raiseIfNull (nameof oldValue) oldValue
109109
raiseIfNull (nameof source) source
110110
#endif
111-
source |> Array.toSeq |> Seq.replace oldValue newValue |> Seq.toArray : 'T []
111+
source |> Seq.replace oldValue newValue |> ResizeArray
112112

113113
#if !FABLE_COMPILER
114114

@@ -121,15 +121,15 @@ module ResizeArray =
121121
/// <returns>
122122
/// The index of the slice.
123123
/// </returns>
124-
let findSliceIndex (slice: _ []) (source: _ []) =
124+
let findSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int =
125125
#if !NET45
126126
raiseIfNull (nameof slice) slice
127127
raiseIfNull (nameof source) source
128128
#endif
129129

130-
let index = Internals.FindSliceIndex.arrayImpl slice source
130+
let index = Internals.FindSliceIndex.seqImpl slice source
131131
if index = -1 then
132-
ArgumentException("The specified slice was not found in the sequence.") |> raise
132+
invalidArg (nameof slice) "The specified slice was not found in the sequence."
133133
else
134134
index
135135

@@ -140,13 +140,13 @@ module ResizeArray =
140140
/// <returns>
141141
/// The index of the slice or <c>None</c>.
142142
/// </returns>
143-
let tryFindSliceIndex (slice: _ []) (source: _ []) =
143+
let tryFindSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int option =
144144
#if !NET45
145145
raiseIfNull (nameof slice) slice
146146
raiseIfNull (nameof source) source
147147
#endif
148148

149-
let index = Internals.FindSliceIndex.arrayImpl slice source
149+
let index = Internals.FindSliceIndex.seqImpl slice source
150150
if index = -1 then None else Some index
151151

152152
/// <summary>
@@ -158,10 +158,10 @@ module ResizeArray =
158158
/// <returns>
159159
/// The index of the slice.
160160
/// </returns>
161-
let findLastSliceIndex (slice: _ []) (source: _ []) =
162-
let index = Internals.FindLastSliceIndex.arrayImpl slice source
161+
let findLastSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int =
162+
let index = Internals.FindLastSliceIndex.seqImpl slice source
163163
if index = -1 then
164-
ArgumentException("The specified slice was not found in the sequence.") |> raise
164+
invalidArg (nameof slice) "The specified slice was not found in the sequence."
165165
else
166166
index
167167

@@ -172,8 +172,8 @@ module ResizeArray =
172172
/// <returns>
173173
/// The index of the slice or <c>None</c>.
174174
/// </returns>
175-
let tryFindLastSliceIndex (slice: _ []) (source: _ []) =
176-
let index = Internals.FindLastSliceIndex.arrayImpl slice source
175+
let tryFindLastSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int option =
176+
let index = Internals.FindLastSliceIndex.seqImpl slice source
177177
if index = -1 then None else Some index
178178
#endif
179179

@@ -184,14 +184,14 @@ module ResizeArray =
184184
/// <returns>
185185
/// A tuple with both resulting arrays.
186186
/// </returns>
187-
let partitionMap (mapper: 'T -> Choice<'T1,'T2>) (source: array<'T>) =
187+
let partitionMap (mapper: 'T -> Choice<'T1,'T2>) (source: ResizeArray<'T>) : ResizeArray<'T1> * ResizeArray<'T2> =
188188
#if !NET45
189189
raiseIfNull (nameof source) source
190190
#endif
191191

192192
let (x, y) = ResizeArray (), ResizeArray ()
193-
Array.iter (mapper >> function Choice1Of2 e -> x.Add e | Choice2Of2 e -> y.Add e) source
194-
x.ToArray (), y.ToArray ()
193+
iter (mapper >> function Choice1Of2 e -> x.Add e | Choice2Of2 e -> y.Add e) source
194+
x, y
195195

196196
/// <summary>Safely build a new ResizeArray whose elements are the results of applying the given function
197197
/// to each of the elements of the two ResizeArrays pairwise.</summary>

0 commit comments

Comments
 (0)