Table of contents
TOC
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 8/18/2017
|
1 Contributor

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)

Syntax

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

// Usage:
func2 << func1

Parameters

func2 Type: 'T2 -> 'T3

The second function to apply.

func1 Type: 'T1 -> 'T2

The first function to apply.

Return Value

The composition of the input functions.

Remarks

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

Example

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")

Output:

abc.append2.append1
abc.append3.append2.append1
myfile.txt

Platforms

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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Core.Operators Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2018 Microsoft