-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathIReadOnlyCollection.fs
More file actions
20 lines (16 loc) · 1.03 KB
/
IReadOnlyCollection.fs
File metadata and controls
20 lines (16 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace FSharpPlus
/// Additional operations on IReadOnlyCollection<'T>
[<RequireQualifiedAccess>]
module IReadOnlyCollection =
open System.Collections.Generic
[<GeneralizableValue>]
let empty<'T> = [||] :> IReadOnlyCollection<'T>
let ofArray (source: 'T[] ) = source :> IReadOnlyCollection<'T>
let ofList (source: 'T list) = source :> IReadOnlyCollection<'T>
let ofSeq (source: seq<'T>) = source |> Array.ofSeq :> IReadOnlyCollection<'T>
let map mapping (source: IReadOnlyCollection<'T>) = Seq.map mapping source |> Seq.toArray :> IReadOnlyCollection<'U>
/// <summary>Applies the given function to each element of the collection.</summary>
/// <param name="action">The function to apply to elements from the input collection.</param>
/// <param name="source">The input collection.</param>
let iter action (source: IReadOnlyCollection<'T>) = Seq.iter action source
let isEmpty (source: IReadOnlyCollection<'T>) = source.Count = 0