Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rexcfnghk committed Jun 14, 2024
1 parent 976ecaf commit 0fd736c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
2 changes: 0 additions & 2 deletions DataParser.Console/Core.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module DataParser.Console.Core

open System.Collections.Generic

type FormatName = FormatName of string

type Error =
Expand Down
2 changes: 1 addition & 1 deletion DataParser.Console/FileRead.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let getDataFileFormat formatLines (filePath, fileName) =
return { Name = dataFileName; FormatLines = formatLines; FilePath = filePath }
}

let getDataFiles folderPath =
let readDataFiles folderPath =
seq {
for file in Directory.GetFiles(folderPath, "*.txt") do
(file, Path.GetFileNameWithoutExtension file)
Expand Down
40 changes: 15 additions & 25 deletions DataParser.Console/Program.fs
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
open System
open DataParser.Console.FileRead
open DataParser.Console.FileWrite
open DataParser.Console.DataFiles
open DataParser.Console.Core

[<Literal>]
let specPath = "./specs"
let specFolderPath = "./specs"

[<Literal>]
let dataPath = "./data"
let dataFolderPath = "./data"

[<Literal>]
let outputPath = "./output"
let outputFolderPath = "./output"

let okHandler = writeOutputFile outputPath
let okHandler = writeOutputFile outputFolderPath

let errorHandler = List.iter (eprintfn "Error occurred during processing: %+A")

let program = result {
printfn "Reading spec files..."
let specs = readAllSpecFiles specPath

printfn "Retrieving data files..."
let dataFiles = getDataFiles dataPath

printfn "Parsing data files..."
let dataFileParsedResults = Seq.map (mapDataFilePath specs) dataFiles

printfn "Writing to output..."
Seq.iter (Result.biFoldMap okHandler errorHandler) dataFileParsedResults

return ()
}

match program with
| Error e -> errorHandler e
| Ok _ -> ()
printfn "Reading spec files..."
let specs = readAllSpecFiles specFolderPath

printfn "Retrieving data files..."
let dataFiles = readDataFiles dataFolderPath

printfn "Parsing data files..."
let dataFileParsedResults = Seq.map (mapDataFilePath specs) dataFiles

printfn "Writing to output..."
Seq.iter (Result.biFoldMap okHandler errorHandler) dataFileParsedResults

printfn "Processing complete. Press Enter to exit."
ignore <| Console.ReadLine()

0 comments on commit 0fd736c

Please sign in to comment.