Skip to content

Commit 9b34ece

Browse files
committed
+ Functions for IList and IReadOnlyList
1 parent 466d3e1 commit 9b34ece

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/FSharpPlus/Control/Alternative.fs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
namespace FSharpPlus.Control
2-
31
/// <namespacedoc>
42
/// <summary>
53
/// Generally internal and not useful directly - contains generic function overloaded implementations.
64
/// </summary>
75
/// </namespacedoc>
6+
namespace FSharpPlus.Control
87

98
#if (!FABLE_COMPILER || FABLE_COMPILER_3) && !FABLE_COMPILER_4
109

src/FSharpPlus/Extensions/IList.fs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace FSharpPlus
22

3-
#if !FABLE_COMPILER
4-
53
/// Additional operations IList<'T>
64
[<RequireQualifiedAccess>]
75
module IList =
@@ -14,4 +12,8 @@ module IList =
1412
/// <returns>The list converted to a System.Collections.Generic.IReadOnlyList</returns>
1513
let toIReadOnlyList (source: IList<_>) = ReadOnlyCollection source :> IReadOnlyList<_>
1614

17-
#endif
15+
let ofArray (source: 'T[] ) = source :> IList<'T>
16+
let ofList (source: 'T list) = source |> Array.ofList :> IList<'T>
17+
let ofSeq (source: seq<'T>) = source |> Array.ofSeq :> IList<'T>
18+
let map mapping (source: IList<'T>) = Seq.map mapping source |> Seq.toArray :> IList<'U>
19+
let iter mapping (source: IList<'T>) = Seq.iter mapping source

src/FSharpPlus/Extensions/IReadOnlyList.fs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ module IReadOnlyList =
1919
if 0 <= i && i < source.Count then
2020
source |> Array.ofSeq |> setNth i value |> ofArray |> Some
2121
else None
22+
23+
let ofList (source: 'T list) = source |> Array.ofList |> IList.toIReadOnlyList
24+
let ofSeq (source: seq<'T>) = source |> Array.ofSeq |> IList.toIReadOnlyList
25+
2226
#endif
2327

2428
let tryItem i (source: IReadOnlyList<_>) =
2529
if 0 <= i && i < source.Count then Some source.[i]
26-
else None
30+
else None
31+
32+
let map mapping (source: IReadOnlyList<'T>) : IReadOnlyList<'U> = Seq.map mapping source |> Seq.toArray |> IList.toIReadOnlyList
33+
let iter mapping (source: IReadOnlyList<'T>) = Seq.iter mapping source

0 commit comments

Comments
 (0)