Skip to content

Commit

Permalink
NonEmpty[List|Seq] #if !NET45
Browse files Browse the repository at this point in the history
  • Loading branch information
wallymathieu committed Nov 12, 2024
1 parent f3ed1af commit 5f4fde8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/FSharpPlus/Data/NonEmptyList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ module NonEmptyList =
let init (count: int) (initializer: int -> 'T) : NonEmptyList<'T> =
Seq.init count initializer |> ofSeq

#if !NET45
/// <summary>Inserts an element at the specified index.</summary>
/// <param name="index">The index at which to insert the element.</param>
/// <param name="value">The value to insert.</param>
Expand All @@ -509,6 +510,7 @@ module NonEmptyList =
/// <returns>The result list.</returns>
let insertManyAt (index: int) (values: seq<'T>) (list: NonEmptyList<'T>) : NonEmptyList<'T> =
Seq.insertManyAt index values list |> ofSeq
#endif

/// <summary>Returns the element at the specified index.</summary>
/// <param name="index">The index of the element to retrieve.</param>
Expand Down Expand Up @@ -673,6 +675,7 @@ module NonEmptyList =
let inline range (start: 'T) stop =
create start (List.drop 1 [start..stop])

#if !NET45
/// <summary>Removes the element at the specified index.</summary>
/// <param name="index">The index of the element to remove.</param>
/// <param name="list">The input list.</param>
Expand Down Expand Up @@ -704,7 +707,8 @@ module NonEmptyList =
/// <exception cref="System.ArgumentException">Thrown when removing the items results in an empty list.</exception>
let removeManyAt (index: int) (count: int) (list: NonEmptyList<'T>) : NonEmptyList<'T> =
list |> Seq.removeManyAt index count |> ofSeq

#endif

/// <summary>Creates a list that contains one repeated value.</summary>
/// <param name="count">The number of elements.</param>
/// <param name="value">The value to replicate.</param>
Expand Down Expand Up @@ -946,15 +950,17 @@ module NonEmptyList =
/// <returns>A tuple containing the three lists.</returns>
let unzip3 (list: NonEmptyList<'T1 * 'T2 * 'T3>) : NonEmptyList<'T1> * NonEmptyList<'T2> * NonEmptyList<'T3> =
list |> toList |> List.unzip3 |> fun (a, b, c) -> (ofList a, ofList b, ofList c)


#if !NET45
/// <summary>Updates the element at the specified index.</summary>
/// <param name="index">The index of the element to update.</param>
/// <param name="value">The new value.</param>
/// <param name="list">The input list.</param>
/// <returns>The result list.</returns>
let updateAt (index: int) (value: 'T) (list: NonEmptyList<'T>) : NonEmptyList<'T> =
Seq.updateAt index value list |> ofSeq

#endif

/// <summary>Returns a list that contains the elements of the list for which the given function returns <c>true</c>.</summary>
/// <param name="predicate">A function to test each element of the list.</param>
/// <param name="list">The input list.</param>
Expand Down
14 changes: 9 additions & 5 deletions src/FSharpPlus/Data/NonEmptySeq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ module NonEmptySeq =
/// <returns>The result sequence.</returns>
let initInfinite initializer =
Seq.initInfinite initializer |> unsafeOfSeq

#if !NET45
/// <summary>Inserts an element at the specified index.</summary>
/// <param name="index">The index at which to insert the element.</param>
/// <param name="value">The value to insert.</param>
Expand All @@ -493,7 +493,7 @@ module NonEmptySeq =
/// <returns>The result sequence.</returns>
let insertManyAt (index: int) (values: seq<'T>) (source: NonEmptySeq<'T>) : NonEmptySeq<'T> =
Seq.insertManyAt index values source |> unsafeOfSeq

#endif
/// <summary>Returns the element at the specified index.</summary>
/// <param name="index">The index of the element to retrieve.</param>
/// <param name="source">The input sequence.</param>
Expand Down Expand Up @@ -696,6 +696,7 @@ module NonEmptySeq =
let reduceBack (reduction: 'T -> 'T -> 'T) (source: NonEmptySeq<'T>) =
Seq.reduceBack reduction source

#if !NET45
/// <summary>Removes the element at the specified index.</summary>
/// <param name="index">The index of the element to remove.</param>
/// <param name="source">The input sequence.</param>
Expand Down Expand Up @@ -727,7 +728,8 @@ module NonEmptySeq =
/// <exception cref="System.ArgumentException">Thrown when removing the items results in an empty sequence.</exception>
let removeManyAt (index: int) (count: int) (source: NonEmptySeq<'T>) : NonEmptySeq<'T> =
Seq.removeManyAt index count source |> ofSeq

#endif

/// <summary>Creates a sequence that contains one repeated value.</summary>
/// <param name="count">The number of elements.</param>
/// <param name="value">The value to replicate.</param>
Expand Down Expand Up @@ -1040,15 +1042,17 @@ module NonEmptySeq =
/// <returns>A tuple containing the three sequences.</returns>
let unzip3 (source: NonEmptySeq<'T1 * 'T2 * 'T3>) : NonEmptySeq<'T1> * NonEmptySeq<'T2> * NonEmptySeq<'T3> =
source |> Seq.toList |> List.unzip3 |> fun (a, b, c) -> (unsafeOfSeq a, unsafeOfSeq b, unsafeOfSeq c)


#if !NET45
/// <summary>Updates the element at the specified index.</summary>
/// <param name="index">The index of the element to update.</param>
/// <param name="value">The new value.</param>
/// <param name="source">The input sequence.</param>
/// <returns>The result sequence.</returns>
let updateAt (index: int) (value: 'T) (source: NonEmptySeq<'T>) : NonEmptySeq<'T> =
Seq.updateAt index value source |> unsafeOfSeq

#endif

/// <summary>Returns a sequence that contains the elements of the sequence for which the given function returns <c>true</c>.</summary>
/// <param name="predicate">A function to test each element of the sequence.</param>
/// <param name="source">The input sequence.</param>
Expand Down

0 comments on commit 5f4fde8

Please sign in to comment.