Skip to content

Instantly share code, notes, and snippets.

@fcallejon
Created July 28, 2018 11:58
Show Gist options
  • Select an option

  • Save fcallejon/06155ed65999d3b2874d20a3b6207e90 to your computer and use it in GitHub Desktop.

Select an option

Save fcallejon/06155ed65999d3b2874d20a3b6207e90 to your computer and use it in GitHub Desktop.
Continuation for the F#101
// REPL https://repl.it/@FernandoCallejo/FSharp101-Pipes
open System
// partially function application as we saw previously
let printItems items = printfn "%i"
// Basic Pipes
let items = [|35;66;1;0;83;9;217;3;8;-3;-12;09;2|]
printItems items |> ignore
// pass the items array to be sorted
let orderItems = items |> Array.sort
printItems orderItems |> ignore
// Back Pipe
let orderItemsBackPipe = Array.sort <| items
printItems orderItemsBackPipe |> ignore
// Composition Pipe
let createDynamicArray q =
let tmpArray = Array.create q 0
let rnd = new Random(DateTime.UtcNow.Millisecond)
let setArrayItem = Array.set tmpArray
for i in 0 .. tmpArray.Length - 1 do
setArrayItem i (rnd.Next(200))
tmpArray
// compose a function to create an array and sort
let createAndSort = createDynamicArray >> Array.sort
let createAndSortBackwards = Array.sort << createDynamicArray
let sortedArray = createAndSort 30
printItems sortedArray |> ignore
let sortedArrayBackwards = createAndSortBackwards 20
printItems sortedArrayBackwards |> ignore
// next: Discriminators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment