-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from davidchambers/return-type
update return type
- Loading branch information
Showing
26 changed files
with
803 additions
and
919 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.