Skip to content

Commit

Permalink
Fix comment for paramListToForm
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrinkmeier committed Apr 25, 2024
1 parent 2189989 commit cbdbe4f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Web/Scotty/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,10 @@ formData = do
Left err -> throwIO $ MalformedForm err
Right value -> return value
where
-- This rather contrived implementation uses cons and reverse to avoid quadratic complexity (e.g. using HashMap.insertWith (++)).
-- It iterates over all parameters, prepending values for duplicate keys and reverses all hashmap entries afterwards.
-- This rather contrived implementation uses cons and reverse to avoid
-- quadratic complexity when constructing a Form from a list of Param.
-- It's equivalent to using HashMap.insertWith (++) which does have
-- quadratic complexity due to appending at the end of list.
paramListToForm :: [Param] -> Form
paramListToForm = Form . fmap reverse . foldl' (\f (k, v) -> HashMap.alter (prependValue v) k f) HashMap.empty

Expand Down

0 comments on commit cbdbe4f

Please sign in to comment.