NameValueCollection extensions

30 views
Skip to first unread message

Ryan Riley

unread,
Apr 11, 2012, 12:16:26 AM4/11/12
to fsharpx
I was looking through the NameValueCollection extensions and noticed that we have both added extensions and created a discrepancy. The toLookup uses the toSeq method, which flattens the inner collection. However, the asLookup leaves the inner collection intact. Should we amend toSeq to work the same? I was also wondering about the inner collection on toList. It's naturally an array, which we hide in toSeq. Would the following changes be worthwhile?

    /// <summary>
    /// Returns a <see cref="NameValueCollection"/> as a sequence of key-value pairs.
    /// </summary>
    /// <param name="a"></param>
    [<Extension>]
    [<CompiledName("ToArray")>]
    let toArray (a: NameValueCollection) =
        a.AllKeys |> Array.map (fun k -> k, a.GetValues k)
 
    /// <summary>
    /// Returns a <see cref="NameValueCollection"/> as a sequence of key-value pairs.
    /// </summary>
    /// <param name="a"></param>
    [<Extension>]
    [<CompiledName("ToEnumerable")>]
    let toSeq (a: NameValueCollection) =
        a.AllKeys |> Seq.map (fun k -> k, a.GetValues k :> seq<string>)
 
    /// <summary>
    /// Returns a <see cref="NameValueCollection"/> as a list of key-value pairs.
    /// </summary>
    /// <param name="a"></param>
    let inline toList (a: NameValueCollection) =
        a.AllKeys |> List.ofArray |> List.map (fun k -> k, a.GetValues k |> List.ofArray)
Reply all
Reply to author
Forward
0 new messages