diff --git a/src/FSharpPlus/Extensions/IList.fs b/src/FSharpPlus/Extensions/IList.fs index f05ba64f5..641e1e74c 100644 --- a/src/FSharpPlus/Extensions/IList.fs +++ b/src/FSharpPlus/Extensions/IList.fs @@ -1,6 +1,5 @@ namespace FSharpPlus -#if !FABLE_COMPILER /// Additional operations IList<'T> [] @@ -9,9 +8,17 @@ module IList = open System.Collections.ObjectModel open System.Collections.Generic +#if !FABLE_COMPILER /// Converts an IList to an IReadOnlyList (from System.Collections.Generic). /// The System.Collections.Generic.IList /// The list converted to a System.Collections.Generic.IReadOnlyList let toIReadOnlyList (source: IList<_>) = ReadOnlyCollection source :> IReadOnlyList<_> #endif + + let ofArray (source: 'T[] ) = source :> IList<'T> + let ofList (source: 'T list) = source |> Array.ofList :> IList<'T> + let ofSeq (source: seq<'T>) = source |> Array.ofSeq :> IList<'T> + let map mapping (source: IList<'T>) = Seq.map mapping source |> Seq.toArray :> IList<'U> + let iter mapping (source: IList<'T>) = Seq.iter mapping source + diff --git a/src/FSharpPlus/Extensions/IReadOnlyList.fs b/src/FSharpPlus/Extensions/IReadOnlyList.fs index b0910bf58..e4ad6c2c2 100644 --- a/src/FSharpPlus/Extensions/IReadOnlyList.fs +++ b/src/FSharpPlus/Extensions/IReadOnlyList.fs @@ -8,7 +8,11 @@ module IReadOnlyList = #if !FABLE_COMPILER let ofArray (source: 'T array) = IList.toIReadOnlyList source + let ofList (source: 'T list) = source |> Array.ofList |> IList.toIReadOnlyList + let ofSeq (source: seq<'T>) = source |> Array.ofSeq |> IList.toIReadOnlyList + #endif + let toArray (source: IReadOnlyList<'T>) = Array.ofSeq source #if !FABLE_COMPILER @@ -19,8 +23,13 @@ module IReadOnlyList = if 0 <= i && i < source.Count then source |> Array.ofSeq |> setNth i value |> ofArray |> Some else None + + let map mapping (source: IReadOnlyList<'T>) : IReadOnlyList<'U> = Seq.map mapping source |> Seq.toArray |> IList.toIReadOnlyList + #endif let tryItem i (source: IReadOnlyList<_>) = if 0 <= i && i < source.Count then Some source.[i] - else None \ No newline at end of file + else None + + let iter mapping (source: IReadOnlyList<'T>) = Seq.iter mapping source \ No newline at end of file