Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rexcfnghk committed Jun 16, 2024
1 parent 10a0e52 commit ca42487
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions DataParser.Console/FileRead.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ let readDataFiles folderPath =
}

let getDataFileFormats resultMap =
let folder (resultMap as ResultMap specs) state (filePath, fileName) =
let folder state (filePath, fileName) =
match parseDataFileName fileName with
| Error e -> Map.add filePath (Error e) state
| Ok (DataFileName (formatName, _)) ->
let r =
match Map.tryFind formatName specs with
let dataFileFormatResult =
match ResultMap.tryFind formatName resultMap with
| Some formatLines ->
Result.bind (flip getDataFileFormat (filePath, fileName)) formatLines
| None -> Error [FileFormatNotFound (ResultMap.keys resultMap, formatName)]
Map.add filePath r state
Map.add filePath dataFileFormatResult state

Seq.fold (folder resultMap) Map.empty
ResultMap << Seq.fold folder Map.empty

5 changes: 1 addition & 4 deletions DataParser.Console/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ printfn "Retrieving data files..."
let dataFiles = readDataFiles dataFolderPath

printfn "Parsing data files..."
let parsedDateFileFormats =
dataFiles
|> getDataFileFormats specs
|> ResultMap
let parsedDateFileFormats = getDataFileFormats specs dataFiles

let dataFileParsedResults =
ResultMap.bindResult parseDataFile parsedDateFileFormats
Expand Down
3 changes: 3 additions & 0 deletions DataParser.Console/ResultMap.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module ResultMap =

let keys (ResultMap x) = Set.ofSeq (Map.keys x)

let tryFind key (ResultMap m) =
Map.tryFind key m

let biIter f g (ResultMap x) =
let go k = function Ok v -> f k v | Error e -> g k e
Map.iter go x
Expand Down

0 comments on commit ca42487

Please sign in to comment.