File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
src/FSharpPlus/Extensions Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 11namespace FSharpPlus
22
3- #if ! FABLE_ COMPILER
43
54/// Additional operations IList<'T>
65[<RequireQualifiedAccess>]
@@ -9,9 +8,17 @@ module IList =
98 open System.Collections .ObjectModel
109 open System.Collections .Generic
1110
11+ #if ! FABLE_ COMPILER
1212 /// <summary>Converts an IList to an IReadOnlyList (from System.Collections.Generic).</summary>
1313 /// <param name="source">The System.Collections.Generic.IList</param>
1414 /// <returns>The list converted to a System.Collections.Generic.IReadOnlyList</returns>
1515 let toIReadOnlyList ( source : IList < _ >) = ReadOnlyCollection source :> IReadOnlyList<_>
1616
1717#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 =
88 #if ! FABLE_ COMPILER
99
1010 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+
1114 #endif
15+
1216 let toArray ( source : IReadOnlyList < 'T >) = Array.ofSeq source
1317
1418 #if ! FABLE_ COMPILER
@@ -19,8 +23,13 @@ module IReadOnlyList =
1923 if 0 <= i && i < source.Count then
2024 source |> Array.ofSeq |> setNth i value |> ofArray |> Some
2125 else None
26+
27+ let map mapping ( source : IReadOnlyList < 'T >) : IReadOnlyList < 'U > = Seq.map mapping source |> Seq.toArray |> IList.toIReadOnlyList
28+
2229 #endif
2330
2431 let tryItem i ( source : IReadOnlyList < _ >) =
2532 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