Skip to content

Commit

Permalink
feat: add JSDoc metadata to array and predicate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorales committed Oct 26, 2023
1 parent 728a22b commit 775231b
Show file tree
Hide file tree
Showing 4 changed files with 774 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-flowers-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'funkcia': patch
---

Add JSDoc data and examples for Array and Predicate methods
80 changes: 39 additions & 41 deletions src/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,6 @@ describe('Array', () => {
});

describe('getters', () => {
describe('take', () => {
describe('data-first', () => {
it('returns a new array with only the amount to be taken', () => {
expect(A.take([1, 2, 3], 2)).toEqual([1, 2]);
});
});

describe('data-last', () => {
it('returns a new array with only the amount to be taken', () => {
expect(pipe([1, 2, 3], A.take(2))).toEqual([1, 2]);
});
});
});

describe('takeWhile', () => {
describe('data-first', () => {
it('returns a new array with all elements until the first index that does not satisfy the predicate', () => {
expect(A.takeWhile([1, 2, 3, 2, 1], (number) => number < 3)).toEqual([
1, 2,
]);
});
});

describe('data-last', () => {
it('returns a new array with all elements until the first index that does not satisfy the predicate', () => {
expect(
pipe(
[1, 2, 3, 2, 1],
A.takeWhile((number) => number < 3),
),
).toEqual([1, 2]);
});
});
});

describe('head', () => {
it('returns a Some with the first element if the array is not empty', () => {
expect(A.head([1, 2, 3, 4, 5])).toMatchOption(O.some(1));
Expand Down Expand Up @@ -226,6 +191,41 @@ describe('Array', () => {
});
});

describe('take', () => {
describe('data-first', () => {
it('returns a new array with only the amount to be taken', () => {
expect(A.take([1, 2, 3], 2)).toEqual([1, 2]);
});
});

describe('data-last', () => {
it('returns a new array with only the amount to be taken', () => {
expect(pipe([1, 2, 3], A.take(2))).toEqual([1, 2]);
});
});
});

describe('takeWhile', () => {
describe('data-first', () => {
it('returns a new array with all elements until the first index that does not satisfy the predicate', () => {
expect(A.takeWhile([1, 2, 3, 2, 1], (number) => number < 3)).toEqual([
1, 2,
]);
});
});

describe('data-last', () => {
it('returns a new array with all elements until the first index that does not satisfy the predicate', () => {
expect(
pipe(
[1, 2, 3, 2, 1],
A.takeWhile((number) => number < 3),
),
).toEqual([1, 2]);
});
});
});

describe('drop', () => {
describe('data-first', () => {
it('returns a new array dropping the amount of items informed', () => {
Expand Down Expand Up @@ -449,9 +449,9 @@ describe('Array', () => {
expect(A.difference([], [])).toEqual([]);

expect(A.difference([1, 2, 3, 4], [])).toEqual([1, 2, 3, 4]);
expect(A.difference([], [3, 4, 5])).toEqual([3, 4, 5]);
expect(A.difference([], [3, 4, 5])).toEqual([]);

expect(A.difference([1, 2, 3, 4], [3, 4, 5])).toEqual([1, 2, 5]);
expect(A.difference([1, 2, 3, 4], [3, 4, 5])).toEqual([1, 2]);
});
});

Expand All @@ -462,11 +462,9 @@ describe('Array', () => {
expect(pipe([1, 2, 3, 4], A.difference<number>([]))).toEqual([
1, 2, 3, 4,
]);
expect(pipe([], A.difference([3, 4, 5]))).toEqual([3, 4, 5]);
expect(pipe([], A.difference([3, 4, 5]))).toEqual([]);

expect(pipe([1, 2, 3, 4], A.difference([3, 4, 5]))).toEqual([
1, 2, 5,
]);
expect(pipe([1, 2, 3, 4], A.difference([3, 4, 5]))).toEqual([1, 2]);
});
});
});
Expand Down
Loading

0 comments on commit 775231b

Please sign in to comment.