Skip to content

Commit 8145680

Browse files
committed
Fixed headTail pattern so that one element arrays match
1 parent 99bdb9f commit 8145680

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailored",
3-
"version": "2.6.1",
3+
"version": "2.6.2",
44
"description": "Pattern matching library",
55
"main": "lib/tailored.js",
66
"jsnext:main": "src/index.js",

src/tailored/resolvers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function resolveVariable(pattern) {
7272

7373
function resolveHeadTail() {
7474
return function(value, args) {
75-
if (!Checks.is_array(value) || value.length < 2) {
75+
if (!Checks.is_array(value) || value.length === 0) {
7676
return false;
7777
}
7878

test/defmatch.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ describe('defmatch', () => {
112112
expect(fn([3, 1, 2, 4]).length).to.equal(3);
113113
});
114114

115+
it('must produce a head and a tail with one element array', () => {
116+
let fn = Tailored.defmatch(
117+
Tailored.clause([Tailored.headTail()], (head, tail) => tail)
118+
);
119+
120+
expect(fn([3]).length).to.equal(0);
121+
});
122+
115123
it('must match on tuple', () => {
116124
let fn = Tailored.defmatch(
117125
Tailored.clause([Tailored.type(Tuple, { values: [1, 2, 3] })], () => 3)

0 commit comments

Comments
 (0)