-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove extraneous combinators #330
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -571,44 +571,6 @@ | |
} | ||
S.T = def('T', {}, [a, Fn(a, b), b], T); | ||
|
||
//# C :: (a -> b -> c) -> b -> a -> c | ||
//. | ||
//. The C combinator. Takes a curried binary function and two values, and | ||
//. returns the result of applying the function to the values in reverse | ||
//. order. Equivalent to Haskell's `flip` function. | ||
//. | ||
//. This function is very similar to [`flip`](#flip), except that its first | ||
//. argument must be curried. This allows it to work with manually curried | ||
//. functions. | ||
//. | ||
//. ```javascript | ||
//. > S.C(S.concat, 'foo', 'bar') | ||
//. 'barfoo' | ||
//. | ||
//. > Z.map(S.C(S.concat, '?'), ['foo', 'bar', 'baz']) | ||
//. ['foo?', 'bar?', 'baz?'] | ||
//. ``` | ||
function C(f, x, y) { | ||
return f(y)(x); | ||
} | ||
S.C = def('C', {}, [Fn(a, Fn(b, c)), b, a, c], C); | ||
|
||
//# B :: (b -> c) -> (a -> b) -> a -> c | ||
//. | ||
//. The B combinator. Takes two functions and a value, and returns the | ||
//. result of applying the first function to the result of applying the | ||
//. second to the value. Equivalent to [`compose`](#compose) and Haskell's | ||
//. `(.)` function. | ||
//. | ||
//. ```javascript | ||
//. > S.B(Math.sqrt, S.inc, 99) | ||
//. 10 | ||
//. ``` | ||
function B(f, g, x) { | ||
return f(g(x)); | ||
} | ||
S.B = def('B', {}, [Fn(b, c), Fn(a, b), a, c], B); | ||
|
||
//# S :: (a -> b -> c) -> (a -> b) -> a -> c | ||
//. | ||
//. The S combinator. Takes a curried binary function, a unary function, | ||
|
@@ -727,21 +689,29 @@ | |
[$.Function([a, b, c, d, e, r]), a, b, c, d, e, r], | ||
curry5); | ||
|
||
//# flip :: ((a, b) -> c) -> b -> a -> c | ||
//# flip :: (a -> b -> c) -> b -> a -> c | ||
//. | ||
//. Takes a binary function and two values, and returns the result of | ||
//. applying the function to the values in reverse order. | ||
//. Takes a curried binary function and two values, and returns the | ||
//. result of applying the function to the values in reverse order. | ||
//. | ||
//. See also [`C`](#C). | ||
//. This is the C combinator from combinatory logic. | ||
//. | ||
//. ```javascript | ||
//. > Z.map(S.flip(Math.pow)(2), [1, 2, 3, 4, 5]) | ||
//. [1, 4, 9, 16, 25] | ||
//. > S.flip(S.concat, 'foo', 'bar') | ||
//. 'barfoo' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
//. ``` | ||
function flip(f, x, y) { | ||
return f(y)(x); | ||
} | ||
S.flip = def('flip', {}, [Fn(a, Fn(b, c)), b, a, c], flip); | ||
|
||
//# flip_ :: ((a, b) -> c) -> b -> a -> c | ||
//. | ||
//. Variant of [`flip`](#flip) which takes an uncurried binary function. | ||
function flip_(f, x, y) { | ||
return f(y, x); | ||
} | ||
S.flip = def('flip', {}, [$.Function([a, b, c]), b, a, c], flip); | ||
S.flip_ = def('flip_', {}, [$.Function([a, b, c]), b, a, c], flip_); | ||
|
||
//# lift :: Functor f => (a -> b) -> f a -> f b | ||
//. | ||
|
@@ -799,20 +769,21 @@ | |
|
||
//# compose :: (b -> c) -> (a -> b) -> a -> c | ||
//. | ||
//. Takes two functions assumed to be unary and a value of any type, | ||
//. and returns the result of applying the first function to the result | ||
//. of applying the second function to the given value. | ||
//. Composes two unary functions, from right to left. Equivalent to Haskell's | ||
//. `(.)` function. | ||
//. | ||
//. In general terms, `compose` performs right-to-left composition of two | ||
//. unary functions. | ||
//. This is the B combinator from combinatory logic. | ||
//. | ||
//. See also [`B`](#B) and [`pipe`](#pipe). | ||
//. See also [`pipe`](#pipe). | ||
//. | ||
//. ```javascript | ||
//. > S.compose(Math.sqrt, S.inc)(99) | ||
//. 10 | ||
//. ``` | ||
S.compose = def('compose', {}, [Fn(b, c), Fn(a, b), a, c], B); | ||
function compose(f, g, x) { | ||
return f(g(x)); | ||
} | ||
S.compose = def('compose', {}, [Fn(b, c), Fn(a, b), a, c], compose); | ||
|
||
//# pipe :: [(a -> b), (b -> c), ..., (m -> n)] -> a -> n | ||
//. | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
'use strict'; | ||
|
||
var S = require('..'); | ||
|
||
var eq = require('./internal/eq'); | ||
var map = require('./internal/map'); | ||
|
||
|
||
test('flip_', function() { | ||
|
||
eq(typeof S.flip_, 'function'); | ||
eq(S.flip_.length, 3); | ||
eq(S.flip_.toString(), 'flip_ :: ((a, b) -> c) -> b -> a -> c'); | ||
|
||
eq(map(S.flip_(Math.pow, 2))([1, 2, 3, 4, 5]), [1, 4, 9, 16, 25]); | ||
eq(S.flip_(S.indexOf, ['a', 'b', 'c', 'd'], 'c'), S.Just(2)); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's append this sentence to the paragraph:
Equivalent to Haskell's
flip
function.We do this for several other functions, and it seems helpful for those coming from Haskell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've only done that for functions where the name in Sanctuary differs from the name in Haskell. Are you sure we want to do it for
flip
, which maps to ..flip
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, fair point. It may not add value. The type signature already indicates that the function takes three arguments (unlike Ramda's version which takes just one).
I leave it to you to decide whether or not to include the sentence. I'm happy either way. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it this way. Once we go down this road we may feel the urge to document how every function relates to Haskell. I'll save us that trouble. ;)