Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/FSharpPlus/Extensions/ResizeArray.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ module ResizeArray =
/// <summary>Applies the given function to each element of the collection.</summary>
/// <param name="action">The function to apply to elements from the input ResizeArray.</param>
/// <param name="source">The input ResizeArray.</param>
let iter (action: 'T -> 'U) (source: ResizeArray<'T>) =
let iter (action: 'T -> unit) (source: ResizeArray<'T>) : unit =
raiseIfNull (nameof source) source

ResizeArray (Seq.map action source)
Seq.iter action source

/// <summary>Applies a ResizeArray of functions to a ResizeArray of values and concatenates them.</summary>
/// <param name="f">The functions.</param>
Expand Down Expand Up @@ -81,16 +81,16 @@ module ResizeArray =
source |> Array.toSeq |> Seq.intersperse element |> Seq.toArray : 'T []

/// Creates a sequence of arrays by splitting the source array on any of the given separators.
let split (separators: seq<_ []>) (source: _ []) =
let split (separators: seq<ResizeArray<'T>>) (source: ResizeArray<'T>) : seq<ResizeArray<'T>> =
raiseIfNull (nameof separators) separators
raiseIfNull (nameof source) source
source |> Array.toSeq |> Seq.split separators |> Seq.map Seq.toArray
source |> Seq.split separators |> Seq.map ResizeArray

/// Replaces a subsequence of the source array with the given replacement array.
let replace (oldValue: _ []) (newValue: _ []) source =
let replace (oldValue: ResizeArray<'T>) (newValue: ResizeArray<'T>) (source: ResizeArray<'T>) : ResizeArray<'T> =
raiseIfNull (nameof oldValue) oldValue
raiseIfNull (nameof source) source
source |> Array.toSeq |> Seq.replace oldValue newValue |> Seq.toArray : 'T []
source |> Seq.replace oldValue newValue |> ResizeArray

#if !FABLE_COMPILER

Expand All @@ -103,13 +103,13 @@ module ResizeArray =
/// <returns>
/// The index of the slice.
/// </returns>
let findSliceIndex (slice: _ []) (source: _ []) =
let findSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int =
raiseIfNull (nameof slice) slice
raiseIfNull (nameof source) source

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

Expand All @@ -120,11 +120,11 @@ module ResizeArray =
/// <returns>
/// The index of the slice or <c>None</c>.
/// </returns>
let tryFindSliceIndex (slice: _ []) (source: _ []) =
let tryFindSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int option =
raiseIfNull (nameof slice) slice
raiseIfNull (nameof source) source

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

/// <summary>
Expand All @@ -136,10 +136,10 @@ module ResizeArray =
/// <returns>
/// The index of the slice.
/// </returns>
let findLastSliceIndex (slice: _ []) (source: _ []) =
let index = Internals.FindLastSliceIndex.arrayImpl slice source
let findLastSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int =
let index = Internals.FindLastSliceIndex.seqImpl slice source
if index = -1 then
ArgumentException("The specified slice was not found in the sequence.") |> raise
invalidArg (nameof slice) "The specified slice was not found in the sequence."
else
index

Expand All @@ -150,8 +150,8 @@ module ResizeArray =
/// <returns>
/// The index of the slice or <c>None</c>.
/// </returns>
let tryFindLastSliceIndex (slice: _ []) (source: _ []) =
let index = Internals.FindLastSliceIndex.arrayImpl slice source
let tryFindLastSliceIndex (slice: ResizeArray<'T>) (source: ResizeArray<'T>) : int option =
let index = Internals.FindLastSliceIndex.seqImpl slice source
if index = -1 then None else Some index
#endif

Expand All @@ -162,12 +162,12 @@ module ResizeArray =
/// <returns>
/// A tuple with both resulting arrays.
/// </returns>
let partitionMap (mapper: 'T -> Choice<'T1,'T2>) (source: array<'T>) =
let partitionMap (mapper: 'T -> Choice<'T1,'T2>) (source: ResizeArray<'T>) : ResizeArray<'T1> * ResizeArray<'T2> =
raiseIfNull (nameof source) source

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

/// <summary>Safely build a new ResizeArray whose elements are the results of applying the given function
/// to each of the elements of the two ResizeArrays pairwise.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpPlus/Extensions/Seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ module Seq =
/// <param name="x3">Third seq.</param>
///
/// <returns>Seq with values returned from mapping function.</returns>
let lift3 f x1 x2 x3 =
let lift3 (f: 'T1 -> 'T2 -> 'T3 -> 'U) (x1: seq<'T1>) (x2: seq<'T2>) (x3: seq<'T3>) : seq<'U> =
Seq.allPairs x2 x3
|> Seq.allPairs x1
|> Seq.map (fun x -> (fst (snd x), snd (snd x), fst x))
|> Seq.map (fun x -> (fst x, fst (snd x), snd (snd x)))
|> Seq.map (fun (x, y, z) -> f x y z)

/// <summary>Applies a function to each element of the collection, starting from the end, threading an accumulator argument
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpPlus/Extensions/String.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ module String =

Seq.contains char source

/// Converts to uppercase -- nullsafe function wrapper for String.ToUpperInvariant method.
/// Converts to uppercase -- function wrapper for String.ToUpperInvariant method.
let toUpper (source: string) =
raiseIfNull (nameof source) source

if isNull source then source else source.ToUpperInvariant ()

/// Converts to lowercase -- nullsafe function wrapper for String.ToLowerInvariant method.
/// Converts to lowercase -- function wrapper for String.ToLowerInvariant method.
let toLower (source: string) =
raiseIfNull (nameof source) source

Expand Down
Loading