Skip to content

Instantly share code, notes, and snippets.

@falfaddaghi
Created March 12, 2021 14:01
Show Gist options
  • Save falfaddaghi/d500437b129cc8797defc301a3430e60 to your computer and use it in GitHub Desktop.
Save falfaddaghi/d500437b129cc8797defc301a3430e60 to your computer and use it in GitHub Desktop.
Functional Programming 5 (Function Composition) In Arabic in F#
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
open System
[<EntryPoint>]
let main argv =
let addOne x = x + 1 //function that adds 1 to x
let Square x = x * x //function that multiplies x by x
let SubtractTen x = x - 10 //function that subtracts 10 from x
// you can think of the |> like a single parameter lambda in c# x=> x
// so x goes to y function
let AddoneSquareSubtractTen x =
x
|>addOne
|>Square
|>SubtractTen
[3;5;7;8]
|>List.map (fun x-> AddoneSquareSubtractTen x)//map is similar to Select in LINQ
|>List.iter (fun x-> printfn "%i" x) //iter is similar to ForEach in LINQ
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment