File tree 2 files changed +18
-2
lines changed
src/FSharpPlus/Extensions
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
1
namespace FSharpPlus
2
2
3
- #if ! FABLE_ COMPILER
4
3
5
4
/// Additional operations IList<'T>
6
5
[<RequireQualifiedAccess>]
@@ -9,9 +8,17 @@ module IList =
9
8
open System.Collections .ObjectModel
10
9
open System.Collections .Generic
11
10
11
+ #if ! FABLE_ COMPILER
12
12
/// <summary>Converts an IList to an IReadOnlyList (from System.Collections.Generic).</summary>
13
13
/// <param name="source">The System.Collections.Generic.IList</param>
14
14
/// <returns>The list converted to a System.Collections.Generic.IReadOnlyList</returns>
15
15
let toIReadOnlyList ( source : IList < _ >) = ReadOnlyCollection source :> IReadOnlyList<_>
16
16
17
17
#endif
18
+
19
+ let ofArray ( source : 'T [] ) = source :> IList< 'T>
20
+ let ofList ( source : 'T list ) = source |> Array.ofList :> IList< 'T>
21
+ let ofSeq ( source : seq < 'T >) = source |> Array.ofSeq :> IList< 'T>
22
+ let map mapping ( source : IList < 'T >) = Seq.map mapping source |> Seq.toArray :> IList< 'U>
23
+ let iter mapping ( source : IList < 'T >) = Seq.iter mapping source
24
+
Original file line number Diff line number Diff line change @@ -8,7 +8,11 @@ module IReadOnlyList =
8
8
#if ! FABLE_ COMPILER
9
9
10
10
let ofArray ( source : 'T array ) = IList.toIReadOnlyList source
11
+ let ofList ( source : 'T list ) = source |> Array.ofList |> IList.toIReadOnlyList
12
+ let ofSeq ( source : seq < 'T >) = source |> Array.ofSeq |> IList.toIReadOnlyList
13
+
11
14
#endif
15
+
12
16
let toArray ( source : IReadOnlyList < 'T >) = Array.ofSeq source
13
17
14
18
#if ! FABLE_ COMPILER
@@ -19,8 +23,13 @@ module IReadOnlyList =
19
23
if 0 <= i && i < source.Count then
20
24
source |> Array.ofSeq |> setNth i value |> ofArray |> Some
21
25
else None
26
+
27
+ let map mapping ( source : IReadOnlyList < 'T >) : IReadOnlyList < 'U > = Seq.map mapping source |> Seq.toArray |> IList.toIReadOnlyList
28
+
22
29
#endif
23
30
24
31
let tryItem i ( source : IReadOnlyList < _ >) =
25
32
if 0 <= i && i < source.Count then Some source.[ i]
26
- else None
33
+ else None
34
+
35
+ let iter mapping ( source : IReadOnlyList < 'T >) = Seq.iter mapping source
You can’t perform that action at this time.
0 commit comments