Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Operators.( << )<'T2,'T3,'T1> Function (F#)

Composes two functions, the function on the right being applied first.

Namespace/Module Path: Microsoft.FSharp.Core.Operators

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
( << ) : ('T2 -> 'T3) -> ('T1 -> 'T2) -> 'T1 -> 'T3

// Usage:
func2 << func1

func2

Type: 'T2 -> 'T3

The second function to apply.

func1

Type: 'T1 -> 'T2

The first function to apply.

The composition of the input functions.

This operator is referred to as the backward or reverse composition operator.

The following example demonstrates the use of the reverse composition operator (<<).

let append1 string1 = string1 + ".append1" 
let append2 string1 = string1 + ".append2" 

// Reverse composition of two functions. 
let appendBothReverse = append1 << append2
printfn "%s" (appendBothReverse "abc")

// Reverse composition of three functions. 
let append3 string1 = string1 + ".append3"
printfn "%s" ((append1 << append2 << append3) "abc")

// Reverse composition of functions with more than one parameter. 
let appendString (string1:string) (string2:string) = string1 + string2

let appendFileExtension extension =
    appendString extension << appendString "." 
printfn "%s" (appendFileExtension "myfile" "txt")
abc.append2.append1
abc.append3.append2.append1
myfile.txt

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Show:
© 2015 Microsoft