-
-
Notifications
You must be signed in to change notification settings - Fork 84
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 #411 from fluture-js/diego/bichain
Add Future.bichain
- Loading branch information
Showing
7 changed files
with
111 additions
and
0 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
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
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
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,18 @@ | ||
import {createTransformation, future, application1, application, func} from './future.js'; | ||
import {call} from './internal/utils.js'; | ||
|
||
export var BichainTransformation = createTransformation(2, 'bichain', { | ||
rejected: function BichainTransformation$rejected(x){ return call(this.$1, x) }, | ||
resolved: function BichainTransformation$resolved(x){ return call(this.$2, x) } | ||
}); | ||
|
||
export function bichain(f){ | ||
var context1 = application1(bichain, func, arguments); | ||
return function bichain(g){ | ||
var context2 = application(2, bichain, func, arguments, context1); | ||
return function bichain(m){ | ||
var context3 = application(3, bichain, future, arguments, context1, context2); | ||
return m._transform(new BichainTransformation(context3, f, g)); | ||
}; | ||
}; | ||
} |
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
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
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,26 @@ | ||
import {bichain} from '../../index.js'; | ||
import {test, assertCrashed, assertRejected, assertResolved, assertValidFuture, eq, throwing, error} from '../util/util.js'; | ||
import {testFunction, functionArg, futureArg} from '../util/props.js'; | ||
import {resolvedSlow, resolved, rejected, rejectedSlow} from '../util/futures.js'; | ||
import {resolve, reject} from '../../index.js'; | ||
|
||
testFunction('bichain', bichain, [functionArg, functionArg, futureArg], assertValidFuture); | ||
|
||
test('runs a bichain transformation on Futures', function (){ | ||
return Promise.all([ | ||
assertResolved(bichain(reject)(resolve)(resolved), 'resolved'), | ||
assertResolved(bichain(reject)(resolve)(resolvedSlow), 'resolvedSlow'), | ||
assertRejected(bichain(resolve)(reject)(resolved), 'resolved'), | ||
assertRejected(bichain(resolve)(reject)(resolvedSlow), 'resolvedSlow'), | ||
assertResolved(bichain(resolve)(reject)(rejected), 'rejected'), | ||
assertResolved(bichain(resolve)(reject)(rejectedSlow), 'rejectedSlow'), | ||
assertRejected(bichain(reject)(resolve)(rejected), 'rejected'), | ||
assertRejected(bichain(reject)(resolve)(rejectedSlow), 'rejectedSlow'), | ||
assertCrashed(bichain(throwing)(reject)(rejected), error), | ||
assertCrashed(bichain(resolve)(throwing)(resolved), error), | ||
]); | ||
}); | ||
|
||
test('displays correctly as string', function (){ | ||
eq(bichain(resolve)(reject)(resolved).toString(), 'bichain (' + resolve.toString() + ') (' + reject.toString() + ') (resolve ("resolved"))'); | ||
}); |