Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
Created November 3, 2012 06:18
Show Gist options
  • Save ApprenticeGC/4006263 to your computer and use it in GitHub Desktop.
Save ApprenticeGC/4006263 to your computer and use it in GitHub Desktop.
Function Composition Demo
open System.IO
let sizeOfFolderComposed folder =
let getFiles folder =
Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
let totalSize =
folder
|> getFiles
|> Array.map (fun file -> new FileInfo(file))
|> Array.map (fun info -> info.Length)
|> Array.sum
// The last statement of function will be used as return statement
totalSize
open System.IO
let sizeOfFolderComposed folder =
let getFiles folder =
Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
// This serves as the last return statement
getFiles
>> Array.map (fun file -> new FileInfo(file))
>> Array.map (fun info -> info.Length)
>> Array.sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment