-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
feat: concatAll #404
Merged
Merged
feat: concatAll #404
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dd14b4d
feat: concatAll
wojpawlik f2e3e45
test(concatAll): use "should notation"
wojpawlik c988c99
test(concatAll): add test for external semigroups
wojpawlik 6d076d4
refactor(concatAll): undefined instead of null for empty foldable
wojpawlik 366f7dc
docs(concatAll): add simpler type signatures
wojpawlik bd8156c
refactor(concatAll): nullSemigroup -> leftIdentitySemigroup
wojpawlik 850a28b
test(concatAll): change a test to pass on Ramda 0.23.0
wojpawlik 1b52f5c
test(concatAll)
wojpawlik 9eec5b9
docs(concatAll)
wojpawlik 1dfc84f
test(concatAll): commented out a problematic test
wojpawlik 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { concat, identical, identity, pipe, when, reduce } from 'ramda'; | ||
|
||
import stubUndefined from './stubUndefined'; | ||
|
||
const leftIdentitySemigroup = { concat: identity }; | ||
|
||
/** | ||
* Returns the result of concatenating the given lists or strings. | ||
* Note: RA.concatAll expects all elements to be of the same type. It will throw an error if you concat an Array with a non-Array value. | ||
* Dispatches to the concat method of the preceding element, if present. Can also concatenate multiple elements of a [fantasy-land compatible semigroup](https://github.com/fantasyland/fantasy-land#semigroup). | ||
* Returns undefined if empty array was passed. | ||
* | ||
* @func concatAll | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.6.0|v2.6.0} | ||
* @category List | ||
* @sig [[a]] -> [a] | Undefined | ||
* @sig [String] -> String | Undefined | ||
* @sig Semigroup s => Foldable s f => f -> s | Undefined | ||
* @param {Array.<Array|string>} list List containing elements that will be concatenated | ||
* @return {Array|string|undefined} Concatenated elements | ||
* @see {@link http://ramdajs.com/docs/#concat|concat} | ||
* @see {@link RA.concatRight|concatRight} | ||
* @see {@link http://ramdajs.com/docs/#unnest|unnest} | ||
* @see {@link http://ramdajs.com/docs/#join|join} | ||
* @example | ||
* | ||
* concatAll([[1], [2], [3]]); //=> [1, 2, 3] | ||
* concatAll(['1', '2', '3']); //=> '123' | ||
* concatAll([]); //=> undefined; | ||
*/ | ||
const concatAll = pipe( | ||
reduce(concat, leftIdentitySemigroup), | ||
when(identical(leftIdentitySemigroup), stubUndefined) | ||
); | ||
|
||
export default concatAll; |
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,46 @@ | ||
import { assert } from 'chai'; | ||
import { NEL, Nil } from 'monet'; | ||
|
||
import * as RA from '../src'; | ||
import eq from './shared/eq'; | ||
|
||
describe('concatAll', function() { | ||
it('should concatenate arrays', function() { | ||
eq(RA.concatAll([[1], [2], [3]]), [1, 2, 3]); | ||
}); | ||
|
||
it('should concatenate strings', function() { | ||
eq(RA.concatAll(['1', '2', '3']), '123'); | ||
}); | ||
|
||
it('should concatenate semigroups', function() { | ||
eq(RA.concatAll([NEL(1), NEL(2)]), NEL(1, NEL(2, Nil))); | ||
}); | ||
|
||
context('when foldable is empty', function() { | ||
specify('should returns undefined', function() { | ||
eq(RA.concatAll([]), undefined); | ||
}); | ||
}); | ||
|
||
context('when foldable contains non-semigroups', function() { | ||
specify('should throw', function() { | ||
assert.throws(() => RA.concatAll([1, 2, null, true]), TypeError); | ||
}); | ||
}); | ||
|
||
/* | ||
// fails on Ramda 0.21 | ||
context('when foldable contains non-compatible semigroups', function() { | ||
specify('should throw', function() { | ||
assert.throws(() => RA.concatAll([[1], '1']), TypeError); | ||
}); | ||
}); | ||
*/ | ||
|
||
context('when passed non-foldable', function() { | ||
specify('should throw', function() { | ||
assert.throws(() => RA.concatAll(null), TypeError); | ||
}); | ||
}); | ||
}); |
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.
Don't forget to align this description with the one I proposed in previous comment