2

NuGet Gallery | Funtom.Linq 0.0.5

 2 years ago
source link: https://www.nuget.org/packages/Funtom.Linq/0.0.5
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

img

Funtom.Linq

Funtom.Linq is a library for F# that is compatible with System.Linq.
This library makes it easier to use pipeline operators and optimizes for FSharp.Core.List<'T> and more.

Naming rules

The method names defined in System.Linq are redefined in camelCase.
For example, 'Select' becomes 'select', and 'ToList' becomes 'toList'.

Usage

In this section, I will show you how to use the System.Linq 'Where' and 'Select' method as an example.

  1. When using System.Linq

    open System.Linq
    
    let xs =
      [ 0..10 ]
        .Where ((>) 5)
        .Select ((*) 2)
    
  2. When using Funtom.Linq

    #r "nuget: Funtom.Linq"
    open Funtom.Linq
    
    let xs =
      [ 0..10 ]
      |> Linq.where ((>) 5)
      |> Linq.select ((*) 2)
    

Performance

Funtom.Linq is intended to be implemented in such a way that its performance is almost equal to or better than that of System.Linq.
Let's compare the performance of 'Select'.

  let xs = [ 0 .. 10000 ]
  let ys = [| 0 .. 10000 |]
  let zs = ResizeArray([| 0 .. 10000 |])
  let ss = seq { 0 .. 10000 }

  [<Benchmark>]
  member __.Fsharp_Seq_map_fslist() = xs |> Seq.map ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Funtom_select_fslist() = xs |> Linq.select ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Linq_Select_fslist() = xs.Select((*) 2).ToArray()
  
  [<Benchmark>]
  member __.Fsharp_Seq_map_array() = ys |> Seq.map ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Funtom_select_array() = ys |> Linq.select ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Linq_Select_array() = ys.Select((*) 2).ToArray()
  
  [<Benchmark>]
  member __.Fsharp_Seq_map_resizearry() = zs |> Seq.map ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Funtom_select_resizearry() = zs |> Linq.select ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Linq_Select_resizearry() = zs.Select((*) 2).ToArray()

  [<Benchmark>]
  member __.Fsharp_Seq_map_seq() = ss |> Seq.map ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Funtom_select_seq() = ss |> Linq.select ((*) 2) |> Linq.toArray

  [<Benchmark>]
  member __.Linq_Select_seq() = ss.Select((*) 2).ToArray()

Result:
image


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK