Skip to content

Commit

Permalink
Merge pull request #164 from davidchambers/return-type
Browse files Browse the repository at this point in the history
update return type
  • Loading branch information
davidchambers authored Feb 23, 2023
2 parents a8b173f + add5bea commit 125a242
Show file tree
Hide file tree
Showing 26 changed files with 803 additions and 919 deletions.
28 changes: 28 additions & 0 deletions lib/Comparison.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Incorrect :: Array Effect -> Array Effect -> Comparison
const Incorrect = actual => expected => ({
tag: 'Incorrect',
actual,
expected,
});

// Correct :: Array Effect -> Comparison
const Correct = actual => ({
tag: 'Correct',
actual,
});

// comparison :: (Array Effect -> Array Effect -> a)
// -> (Array Effect -> a)
// -> Comparison
// -> a
const comparison = incorrect => correct => comparison => {
switch (comparison.tag) {
case 'Incorrect':
return incorrect (comparison.actual) (comparison.expected);
case 'Correct':
return correct (comparison.actual);
}
};


export {Incorrect, Correct, comparison};
31 changes: 31 additions & 0 deletions lib/Effect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Failure :: Any -> Effect
const Failure = exception => ({
tag: 'Failure',
exception,
});

// Success :: Any -> Effect
const Success = value => ({
tag: 'Success',
value,
});

// effect :: (Any -> a) -> (Any -> a) -> Effect -> a
const effect = failure => success => effect => {
switch (effect.tag) {
case 'Failure': return failure (effect.exception);
case 'Success': return success (effect.value);
}
};

// encase :: AnyFunction -> ...Any -> Effect
const encase = f => (...args) => {
try {
return Success (f (...args));
} catch (exception) {
return Failure (exception);
}
};


export {Failure, Success, effect, encase};
5 changes: 5 additions & 0 deletions lib/Line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Line :: Integer -> String -> Line
const Line = number => text => ({number, text});


export {Line};
10 changes: 7 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {comparison} from './Comparison.js';
import doctest from './doctest.js';
import program from './program.js';


Promise.all (
program.args.map (path =>
doctest (program) (path)
.then (results =>
results.reduce ((status, [correct]) => correct ? status : 1, 0)
)
.then (tests => tests.reduce (
(status, test) => comparison (_ => _ => 1)
(_ => status)
(test.comparison),
0
))
)
)
.then (
Expand Down
Loading

0 comments on commit 125a242

Please sign in to comment.