Snippets

Cameron Presley F# - Find Unique line entries in a file

Updated by Former user

File uniqueEntryCounter.fs Modified

  • Ignore whitespace
  • Hide word diff
 let linesRead = readLines "your_file_name_here.txt"
 
 linesRead |> Seq.length |> printfn "There are %i total lines"
-
-linesRead  |> Seq.distinct |> Seq.length |> printfn "There are %i unique entries" 
+linesRead |> Seq.distinct |> Seq.length |> printfn "There are %i unique entries" 
Created by Former user

File uniqueEntryCounter.fs Added

  • Ignore whitespace
  • Hide word diff
+open System.IO
+
+let readLines (filePath:string) = seq {
+    use reader = new StreamReader (filePath)
+    while not reader.EndOfStream do
+        yield reader.ReadLine ()
+}
+
+let linesRead = readLines "your_file_name_here.txt"
+
+linesRead |> Seq.length |> printfn "There are %i total lines"
+
+linesRead  |> Seq.distinct |> Seq.length |> printfn "There are %i unique entries"