Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some random elm code to process a large list...
convertRecordsTask : Task Http.Error (List (List String)) -> Task Http.Error (List TrajectoryPoint)
convertRecordsTask task =
Task.map convertRecords task
convertRecords : List (List String) -> List TrajectoryPoint
convertRecords records =
List.take 10000 records
|> List.map convertRecord
convertRecord : List String -> TrajectoryPoint
convertRecord list =
case list of
sessionId :: orderId :: longitude :: latitude :: _ :: velocity :: timeOfOccurrence :: _ ->
{ sessionId = Result.withDefault 0 (String.toInt sessionId)
, latitude = Result.withDefault 0.0 (String.toFloat latitude)
, longitude = Result.withDefault 0.0 (String.toFloat longitude)
, velocity = Result.withDefault 0.0 (String.toFloat velocity)
, timeOfOccurrence = Result.withDefault 0.0 (String.toFloat timeOfOccurrence)
}
_ ->
{ sessionId = 0
, latitude = 0.0
, longitude = 0.0
, velocity = 0.0
, timeOfOccurrence = 0.0
}
loadTrajectories : String -> Task Http.Error (List TrajectoryPoint)
loadTrajectories path =
CsvLoader.loadAndParseCsv path
|> convertRecordsTask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.