-
-
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
Add S.append #184
Add S.append #184
Conversation
We could restrict |
def('append', | ||
{}, | ||
[a, $.Array(a), $.Array(a)], | ||
function(x, xs) { return xs.concat(x); }); |
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.
I think we need to wrap x
here, currently we have S.append([3, 4], [[1], [2]]); //=> [[1], [2], 3, 4]
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 use xs.concat([x])
, to handle nested arrays correctly:
> [1, 2].concat(3)
[1, 2, 3]
> [1, 2].concat([3])
[1, 2, 3]
> [[1], [2]].concat([3])
[[1], [2], 3]
> [[1], [2]].concat([[3]])
[[1], [2], [3]]
Let's also include a test case to cover this.
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.
Beaten to the punch! Good spotting, Kevin. :)
@svozza I guess semigroup could make sense yes. |
I don't think so, Stefano. The function should work |
@davidchambers right.. so |
Do we not want this to work on strings too? |
I'm not sure this is necessary: > S.append('!', 'abc')
'abc!'
> S.append('!', ['a', 'b', 'c'])
['a', 'b', 'c', '!'] There's also the question of whether |
0504a2d
to
c6ed504
Compare
anything else? |
@@ -3032,6 +3065,8 @@ | |||
[$.Array($.String), $.String], | |||
compose(R.join(''), R.map(concat(_, '\n')))); | |||
|
|||
|
|||
|
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.
👾
6da9370
to
3002ecb
Compare
//# append :: a -> [a] -> [a] | ||
//. | ||
//. Takes a value of any type and a list of values of that type, and | ||
//. returns the result of appending the value to the list. |
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.
In light of #180, we need to make a few changes to preserve consistency:
- change the signature to
a -> Array a -> Array a
; s/a list/an array/
;s/the list/the array/
; and- move the function to the Array section (at the very beginning, let's say).
Much has changed in the few days since you submitted this pull request. I realize I've already asked you to move this function once! There won't usually be this much friction, I promise. :)
It looks as though your tests disappeared in the rebase! |
ebdfd02
to
2804380
Compare
@davidchambers ugh.. tests added again. This whole PR took much longer than I would have anticipated ;) |
@@ -2274,6 +2274,7 @@ | |||
return n < 0 || negativeZero(n) ? Nothing() : slice(0, -n, xs); | |||
}); | |||
|
|||
|
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.
Is this newline intentional?
2804380
to
f913cc1
Compare
Looks good to me, though I haven't kept up with the discussions leading up to this point. I'll leave the final call to @davidchambers. |
@@ -2292,6 +2292,24 @@ | |||
R.pipe(R[name], Just, R.filter(R.gte(_, 0)))); | |||
}; | |||
|
|||
//# append :: a -> Array a -> Array a |
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.
This is still in the List section. This function is Array-specific so belongs in the Array section. Let's do this:
//. ### Array
+ //# append :: a -> Array a -> Array a
+ //.
+ //. Takes a value of any type and an array of values of that type, and
+ //. returns the result of appending the value to the array.
+ //.
+ //. ```javascript
+ //. > S.append(3, [1, 2])
+ //. [1, 2, 3]
+ //.
+ //. > S.append([3, 4], [[1], [2]])
+ //. [[1], [2], [3, 4]]
+ //. ```
+ S.append =
+ def('append',
+ {},
+ [a, $.Array(a), $.Array(a)],
+ function(x, xs) { return xs.concat([x]); });
+
//# find :: (a -> Boolean) -> Array a -> Maybe a
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.
wow i'm close to giving up x__X - The one huge file is driving me bonkers. I don't think I've ever needed so many attempts to get something so trivial done. Sorry.
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.
Even with separate files we'd need to specify the readme order somewhere, but a list of filenames in the makefile would certainly be easier to read. ;)
f913cc1
to
3c7aa32
Compare
Are we good to go now? :-) fingers crossed |
@@ -2292,6 +2292,7 @@ | |||
R.pipe(R[name], Just, R.filter(R.gte(_, 0)))); | |||
}; | |||
|
|||
|
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.
👾
Delete the stray line and I'll merge. :) |
3c7aa32
to
f36353f
Compare
🌳 Thanks, Tobias! |
This adds S.append as suggested by #145
So this is my first contribution and I just naively implemented it as
a -> [a] -> [a]
.