Skip to content

Commit

Permalink
Switch to trampolined partition function
Browse files Browse the repository at this point in the history
  • Loading branch information
deadfoxygrandpa committed Apr 18, 2014
1 parent 5947ca0 commit acc90cb
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ElmTest/Run.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ the output, instead look at the ```runDisplay``` series in ElmTest.Runner
# Run
@docs run, report, pass, fail
-}
-}

import Trampoline (..)

import ElmTest.Assertion (..)
import ElmTest.Test (..)
Expand All @@ -18,9 +20,9 @@ type Report = { results : [Result]

{-| Run a test and get a Result -}
run : Test -> Result
run (TestCase _ assertion) =
run (TestCase _ assertion) =
let runAssertion t m = if t ()
then Nothing
then Nothing
else Just m
in case assertion of
AssertEqual t a b -> runAssertion t <| "Expected: " ++ a ++ "; got: " ++ b
Expand All @@ -41,8 +43,18 @@ fail = not . pass
{-| Run a list of tests and get a Report -}
report : [Test] -> Report
report ts = let results = map run ts
(passes, fails) = partition pass results
(passes, fails) = partitionTrampoline pass results
in { results = results
, passes = passes
, failures = fails
}
}

partitionTrampoline : (a -> Bool) -> [a] -> ([a], [a])
partitionTrampoline f list = trampoline (partitionTrampoline' ([], []) f list)

partitionTrampoline' : ([a], [a]) -> (a -> Bool) -> [a] -> Trampoline ([a], [a])
partitionTrampoline' ((xs, ys) as accum) f list =
case list of
[] -> Done accum
(z::zs) -> let accum' = if f z then (z::xs, ys) else (xs, z::ys)
in Continue (\() -> partitionTrampoline' accum' f zs)

2 comments on commit acc90cb

@maxsnew
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the partition function in the main Elm repo so this shouldn't be necessary now.

@deadfoxygrandpa
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll revert it.

Please sign in to comment.