FSharp.Core.Fluent


FSharp.Core.Fluent is a collection of inlined methods allowing fluent access to all FSharp.Core functions for List, Array, Array2D, Array3D, Seq, Option, String, Event and Observable.

For example, this library adds .map, .filter and many other methods for lists, arrays and sequences:

open FSharp.Core.Fluent

let xs = [ 1 .. 10 ]

xs.map(fun x -> x + 1).filter(fun x -> x > 4).sort()

xs.map(fun x -> x + 1)
  .filter(fun x -> x > 4)
  .sort()

Comparison with non-Fluent style

F# code normally uses curried module functions to access functionality for collections, composed in pipelines:

xs
|> List.map (fun x -> x + 1)
|> List.filter (fun x -> x > 4)

There are reasons F# uses this style of programming by default: for example, module functions can compose nicely (e.g. xs |> List.map (List.map f) ). However "fluent" access can be convenient, especially in rapid investigative programming against existing data. For this reason, this option makes fluent notation an option.

In almost all case, xs.OP(arg) is equivalent to the pipelined xs |> Coll.OP arg. So you can freely interconvert betweeen

xs
|> List.map (fun x -> x + 1)
|> List.filter (fun x -> x > 4)

and

xs.map(fun x -> x + 1)
  .filter(fun x -> x > 4)

You can also use pipeline operations after fluent operations:

xs
  .map(fun x -> x + 1)
  |> List.filter(fun x -> x > 4)
  |> Array.ofList

You can't mix pipelining followed by fluent, and attempting to do so can give obscure errors:

xs
  |> List.map(fun x -> x + 1)
  .filter(fun x -> x > 4)  // ERROR: The field or constructor "filter" is not defined

NOTE: append does the natural thing in fluent form

In the the case of xs.append(ys), the result is "xs then ys" - as expected. However this is different to xs |> List.append ys, which is actually ys then xs due to the way pipelining and currying works.

Usage examples

See this documentation for examples of using a wide range of the functions.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests.

The library is available under MIT license. For more information see the License file in the GitHub repository.

namespace Microsoft.FSharp
namespace Microsoft.FSharp.Core
val xs : int list
Multiple items
module List from Microsoft.FSharp.Collections
<summary>Contains operations for working with values of type <see cref="T:Microsoft.FSharp.Collections.list`1" />.</summary>
<namespacedoc><summary>Operations for collections such as lists, arrays, sets, maps and sequences. See also <a href="https://docs.microsoft.com/dotnet/fsharp/language-reference/fsharp-collection-types">F# Collection Types</a> in the F# Language Guide. </summary></namespacedoc>


--------------------
type List<'T> = | ( [] ) | ( :: ) of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex : rank:int * offset:int -> int member GetSlice : startIndex:int option * endIndex:int option -> 'T list static member Cons : head:'T * tail:'T list -> 'T list member Head : 'T member IsEmpty : bool member Item : index:int -> 'T with get ...
<summary>The type of immutable singly-linked lists.</summary>
<remarks>Use the constructors <c>[]</c> and <c>::</c> (infix) to create values of this type, or the notation <c>[1;2;3]</c>. Use the values in the <c>List</c> module to manipulate values of this type, or pattern match against the values directly. </remarks>
<exclude />
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
<summary>Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection.</summary>
<param name="mapping">The function to transform elements from the input list.</param>
<param name="list">The input list.</param>
<returns>The list of transformed elements.</returns>
val x : int
val filter : predicate:('T -> bool) -> list:'T list -> 'T list
<summary>Returns a new collection containing only the elements of the collection for which the given predicate returns "true"</summary>
<param name="predicate">The function to test the input elements.</param>
<param name="list">The input list.</param>
<returns>A list containing only the elements that satisfy the predicate.</returns>
module Array from Microsoft.FSharp.Collections
<summary>Contains operations for working with arrays.</summary>
<remarks> See also <a href="https://docs.microsoft.com/dotnet/fsharp/language-reference/arrays">F# Language Guide - Arrays</a>. </remarks>
val ofList : list:'T list -> 'T []
<summary>Builds an array from the given list.</summary>
<param name="list">The input list.</param>
<returns>The array of elements from the list.</returns>
val x : 'a (requires member ( + ))