FSharp.Core.Fluent


Usage examples

Seq functions

The fluent-style members for all Seq.* operations are shown below. Some additional fluent functions are available for Array, these are not shown here.

open FSharp.Core.Fluent

module SeqExamples =
    let seq1 = seq { 1 .. 10 }
    let seq2 = seq { 11 .. 20 }

    seq1.append(seq2)
    seq1.averageBy(fun x -> float x)
    seq1.cache()
    seq1.choose(fun x -> if x % 2 = 0 then Some x else None)
    seq1.collect (fun n -> [ n; n + 1 ])
    seq1.countBy(fun x -> x)
    seq1.distinct()
    seq1.distinctBy(fun x -> x)
    seq1.exactlyOne()
    seq1.exists(fun x -> x > 1)
    seq1.filter(fun x -> x > 1)
    seq1.find(fun x -> x > 1)
    seq1.findIndex(fun x -> x > 1)
    seq1.tryFind(fun x -> x > 1)
    seq1.tryFindIndex(fun x -> x > 1)
    seq1.tryPick(fun x -> Some x)
    seq1.fold(3, fun z x -> x + z)
    seq1.forall(fun x -> x > 1)
    seq1.groupBy(fun x -> x)
    seq1.head()
    seq1.iter(fun x -> printfn "%d" x)
    seq1.iteri(fun i x ->  printfn "%d" x)
    seq1.last()
    seq1.length
    seq1.map(fun x -> x + 1)
    seq1.mapi(fun i x -> x + 1)
    seq1.max()
    seq1.maxBy(fun x -> x)
    seq1.min()
    seq1.minBy(fun x -> x)
    seq1.pairwise()
    seq1.pick(fun x -> Some x)
    seq1.readonly()
    seq1.reduce(+)
    seq1.scan(3, fun z x -> x + z)
    seq1.skip(3)
    seq1.skipWhile(fun x -> x > 1)
    seq1.sort()
    seq1.sortBy(fun x -> x)
    seq1.sum()
    seq1.sumBy(fun x -> x)
    seq1.take(3)
    seq1.takeWhile(fun x -> x > 1)
    seq1.toArray()
    seq1.toList()
    seq1.toArray()
    seq1.truncate(3)
    seq1.tryFind(fun x -> x > 1)
    seq1.tryFindIndex(fun x -> x > 1)
    seq1.tryPick(fun x -> Some x)
    seq1.where(fun x -> x > 1)
    seq1.windowed(3)
    seq1.zip(seq2)
    seq1.zip3(seq1,seq2)
    seq1.contains(3)
    seq1.except(seq2)
    seq1.permute(fun x -> x)
    seq1.reduceBack(+)
    seq1.foldBack((fun x z -> x + z), 3)
    seq1.reverse()
    seq1.scanBack((+),3)
    seq1.sortWith(compare)
    seq1.sortDescending()
    seq1.chunkBySize(3)
    seq1.splitInto(3)
    seq1.tryFindIndexBack(fun x -> x > 1)
    seq1.tryFindBack(fun x -> x > 1)
    seq1.tryItem(19)
    seq1.tail()

Array functions

The fluent-style members for Array.* operations are shown below.

module ArrayExamples =
    let array1 = [| 1 .. 10 |]
    let array2 = [| 11 .. 20 |]

    array1.append(array2)
    array1.averageBy(fun x -> float x)
    array1.cache()
    array1.choose(fun x -> if x % 2 = 0 then Some x else None)
    array1.collect (fun n -> [ n; n + 1 ])
    array1.countBy(fun x -> x)
    array1.distinct()
    array1.distinctBy(fun x -> x)
    array1.exactlyOne()
    array1.exists(fun x -> x > 1)
    array1.filter(fun x -> x > 1)
    array1.find(fun x -> x > 1)
    array1.findIndex(fun x -> x > 1)
    array1.tryFind(fun x -> x > 1)
    array1.tryFindIndex(fun x -> x > 1)
    array1.tryPick(fun x -> Some x)
    array1.fold(3, fun z x -> x + z)
    array1.forall(fun x -> x > 1)
    array1.groupBy(fun x -> x)
    array1.head()
    array1.iter(fun x -> printfn "%d" x)
    array1.iteri(fun i x ->  printfn "%d" x)
    array1.last()
    array1.length
    array1.map(fun x -> x + 1)
    array1.mapi(fun i x -> x + 1)
    array1.max()
    array1.maxBy(fun x -> x)
    array1.min()
    array1.minBy(fun x -> x)
    array1.pairwise()
    array1.pick(fun x -> Some x)
    array1.readonly()
    array1.reduce(+)
    array1.scan(3, fun z x -> x + z)
    array1.skip(3)
    array1.skipWhile(fun x -> x > 1)
    array1.sort()
    array1.sortBy(fun x -> x)
    array1.sum()
    array1.sumBy(fun x -> x)
    array1.take(3)
    array1.takeWhile(fun x -> x > 1)
    array1.toArray()
    array1.toList()
    array1.toArray()
    array1.truncate(3)
    array1.tryFind(fun x -> x > 1)
    array1.tryFindIndex(fun x -> x > 1)
    array1.tryPick(fun x -> Some x)
    array1.where(fun x -> x > 1)
    array1.windowed(3)
    array1.zip(array2)
    array1.zip3(array1,array2)
    array1.contains(3)
    array1.except(array2)
    array1.permute(fun x -> x)
    array1.reduceBack(+)
    array1.foldBack((fun x z -> x + z), 3)
    array1.reverse()
    array1.scanBack((+),3)
    array1.sortWith(compare)
    array1.sortDescending()
    array1.chunkBySize(3)
    array1.splitInto(3)
    array1.tryFindIndexBack(fun x -> x > 1)
    array1.tryFindBack(fun x -> x > 1)
    array1.tryItem(19)
    array1.tail()

List functions

The fluent-style members for List.* operations are shown below.

module ListExamples =
    let list1 = [ 1 .. 10 ]
    let list2 = [ 11 .. 20 ]

    list1.append(list2)
    list1.averageBy(fun x -> float x)
    list1.cache()
    list1.choose(fun x -> if x % 2 = 0 then Some x else None)
    list1.collect (fun n -> [ n; n + 1 ])
    list1.countBy(fun x -> x)
    list1.distinct()
    list1.distinctBy(fun x -> x)
    list1.exactlyOne()
    list1.exists(fun x -> x > 1)
    list1.filter(fun x -> x > 1)
    list1.find(fun x -> x > 1)
    list1.findIndex(fun x -> x > 1)
    list1.tryFind(fun x -> x > 1)
    list1.tryFindIndex(fun x -> x > 1)
    list1.tryPick(fun x -> Some x)
    list1.fold(3, fun z x -> x + z)
    list1.forall(fun x -> x > 1)
    list1.groupBy(fun x -> x)
    list1.head()
    list1.iter(fun x -> printfn "%d" x)
    list1.iteri(fun i x ->  printfn "%d" x)
    list1.last()
    list1.length
    list1.map(fun x -> x + 1)
    list1.mapi(fun i x -> x + 1)
    list1.max()
    list1.maxBy(fun x -> x)
    list1.min()
    list1.minBy(fun x -> x)
    list1.pairwise()
    list1.pick(fun x -> Some x)
    list1.readonly()
    list1.reduce(+)
    list1.scan(3, fun z x -> x + z)
    list1.skip(3)
    list1.skipWhile(fun x -> x > 1)
    list1.sort()
    list1.sortBy(fun x -> x)
    list1.sum()
    list1.sumBy(fun x -> x)
    list1.take(3)
    list1.takeWhile(fun x -> x > 1)
    list1.toArray()
    list1.toList()
    list1.toArray()
    list1.truncate(3)
    list1.tryFind(fun x -> x > 1)
    list1.tryFindIndex(fun x -> x > 1)
    list1.tryPick(fun x -> Some x)
    list1.where(fun x -> x > 1)
    list1.windowed(3)
    list1.zip(list2)
    list1.zip3(list1,list2)
    list1.contains(3)
    list1.except(list2)
    list1.permute(fun x -> x)
    list1.reduceBack(+)
    list1.foldBack((fun x z -> x + z), 3)
    list1.reverse()
    list1.scanBack((+),3)
    list1.sortWith(compare)
    list1.sortDescending()
    list1.chunkBySize(3)
    list1.splitInto(3)
    list1.tryFindIndexBack(fun x -> x > 1)
    list1.tryFindBack(fun x -> x > 1)
    list1.tryItem(19)
    list1.tail()

Option functions

The fluent-style members for Option.* operations are shown below.

module OptionExamples =
    let option1 = Some 1
    let option2 = Some "two"

    option1.exists(fun x -> x > 1)
    option1.filter(fun x -> x > 1)
    option1.fold(3, fun z x -> x + z)
    option1.forall(fun x -> x > 1)
    option1.iter(fun x -> printfn "%d" x)
    option1.map(fun x -> x + 1)
    option1.toArray()
    option1.toList()
    option1.toArray()
    option1.foldBack((fun x z -> x + z), 3)
    option1.bind(fun x -> if x > 1 then None else Some (x+1))
    option1.toNullable()
    option2.toObj()

Observable functions

The fluent-style members for Observable.* operations are shown below.

module ObservableExamples =
    open System
    let ev1 = Event<int>()
    let ev2 = Event<int>()
    let obs1 : IObservable<int> = ev1.Publish :> _
    let obs2 : IObservable<int> = ev2.Publish :> _

    obs1.filter(fun x -> x > 1)
    obs1.map(fun x -> x + 1)
    obs1.add(fun v -> printfn "%d" v)
    obs1.choose(fun v -> if v = 1 then Some 2 else None)
    obs1.merge(obs2)
    obs1.pairwise()
    obs1.partition(fun v -> v > 1)
    obs1.scan((fun a b -> a + b), 0)
    obs1.split(fun v -> if v > 1 then Choice1Of2 v else Choice2Of2 (-v))

Event functions

The fluent-style members for Event.* operations are shown below.

module EventExamples =
    open System
    let e1 = Event<int>()
    let e2 = Event<int>()
    let ev1 = e1.Publish
    let ev2 = e2.Publish

    ev1.filter(fun x -> x > 1)
    ev1.map(fun x -> x + 1)
    ev1.add(fun v -> printfn "%d" v)
    ev1.choose(fun v -> if v = 1 then Some 2 else None)
    ev1.merge(ev2)
    ev1.pairwise()
    ev1.partition(fun v -> v > 1)
    ev1.scan(0, (fun a b -> a + b))
    ev1.split(fun v -> if v > 1 then Choice1Of2 v else Choice2Of2 (-v))

String functions

The fluent-style members for String.* operations are shown below.

module StringExamples =
    open System
    let string1 = "a"

    string1.map(fun x -> 'a')
    string1.mapi(fun i x -> 'a')
    string1.collect(fun x -> "aa")
    string1.pairwise()
    string1.replicate(3)
    string1.length
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Core
val seq1 : seq<int>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>
<summary>Builds a sequence using sequence expression syntax</summary>
<param name="sequence">The input sequence.</param>
<returns>The result sequence.</returns>


--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
<summary>An abbreviation for the CLI type <see cref="T:System.Collections.Generic.IEnumerable`1" /></summary>
<remarks> See the <see cref="T:Microsoft.FSharp.Collections.SeqModule" /> module for further operations related to sequences. See also <a href="https://docs.microsoft.com/dotnet/fsharp/language-reference/sequences">F# Language Guide - Sequences</a>. </remarks>
val seq2 : seq<int>
Multiple items
val float : value:'T -> float (requires member op_Explicit)
<summary>Converts the argument to 64-bit float. This is a direct conversion for all primitive numeric types. For strings, the input is converted using <c>Double.Parse()</c> with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted float</returns>


--------------------
[<Struct>] type float = System.Double
<summary>An abbreviation for the CLI type <see cref="T:System.Double" />.</summary>
<category>Basic Types</category>


--------------------
type float<'Measure> = float
<summary>The type of double-precision floating point numbers, annotated with a unit of measure. The unit of measure is erased in compiled code and when values of this type are analyzed using reflection. The type is representationally equivalent to <see cref="T:System.Double" />.</summary>
<category index="6">Basic Types with Units of Measure</category>
union case Option.Some: Value: 'T -> Option<'T>
<summary>The representation of "Value of type 'T"</summary>
<param name="Value">The input value.</param>
<returns>An option representing the value.</returns>
union case Option.None: Option<'T>
<summary>The representation of "No value"</summary>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
<summary>Print to <c>stdout</c> using the given format, and add a newline.</summary>
<param name="format">The formatter.</param>
<returns>The formatted result.</returns>
val compare : e1:'T -> e2:'T -> int (requires comparison)
<summary>Generic comparison.</summary>
<param name="e1">The first value.</param>
<param name="e2">The second value.</param>
<returns>The result of the comparison.</returns>
val array1 : int []
val array2 : int []
val list1 : int list
val list2 : int list
val option1 : int option
val option2 : string option
namespace System
val ev1 : Event<int>
Multiple items
module Event from Microsoft.FSharp.Control
<summary>Contains operations for working with values of type <see cref="T:Microsoft.FSharp.Control.IEvent`1" />.</summary>
<category index="3">Events and Observables</category>


--------------------
type Event<'T> = new : unit -> Event<'T> member Trigger : arg:'T -> unit member Publish : IEvent<'T>
<summary>Event implementations for the IEvent&lt;_&gt; type.</summary>
<category index="3">Events and Observables</category>


--------------------
type Event<'Delegate,'Args (requires delegate and 'Delegate :> Delegate)> = new : unit -> Event<'Delegate,'Args> member Trigger : sender:obj * args:'Args -> unit member Publish : IEvent<'Delegate,'Args>
<summary>Event implementations for a delegate types following the standard .NET Framework convention of a first 'sender' argument.</summary>
<category index="3">Events and Observables</category>


--------------------
new : unit -> Event<'T>

--------------------
new : unit -> Event<'Delegate,'Args>
Multiple items
val int : value:'T -> int (requires member op_Explicit)
<summary>Converts the argument to signed 32-bit integer. This is a direct conversion for all primitive numeric types. For strings, the input is converted using <c>Int32.Parse()</c> with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted int</returns>


--------------------
[<Struct>] type int = int32
<summary>An abbreviation for the CLI type <see cref="T:System.Int32" />.</summary>
<category>Basic Types</category>


--------------------
type int<'Measure> = int
<summary>The type of 32-bit signed integer numbers, annotated with a unit of measure. The unit of measure is erased in compiled code and when values of this type are analyzed using reflection. The type is representationally equivalent to <see cref="T:System.Int32" />.</summary>
<category>Basic Types with Units of Measure</category>
val ev2 : Event<int>
val obs1 : IObservable<int>
type IObservable<'T> = member Subscribe : observer: IObserver<'T> -> IDisposable
<summary>Defines a provider for push-based notification.</summary>
<typeparam name="T">The object that provides notification information.</typeparam>
property Event.Publish: IEvent<int> with get
<summary>Publishes an observation as a first class value.</summary>
val obs2 : IObservable<int>
union case Choice.Choice1Of2: 'T1 -> Choice<'T1,'T2>
<summary>Choice 1 of 2 choices</summary>
union case Choice.Choice2Of2: 'T2 -> Choice<'T1,'T2>
<summary>Choice 2 of 2 choices</summary>
val e1 : Event<int>
val e2 : Event<int>
val ev1 : IEvent<int>
val ev2 : IEvent<int>
module StringExamples from Fluent
val string1 : string