Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
feat(rest): add rest helper which is the opposite of first
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Mar 5, 2020
1 parent fec3e49 commit cd04181
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,28 @@ type last = <T>(items: T[]) => T | undefined
{% endtab %}
{% endtabs %}
## rest
Given an array, return every item except the first.
{% tabs %}
{% tab title="Usage" %}
```typescript
rest([1, 2, 3]) // [2, 3]
```
{% endtab %}
{% tab title="Type Definition" %}
```typescript
type rest = <T>(items: T[]) => T[]
```
{% endtab %}
{% endtabs %}
## greaterThan
Create a predicate which checks whether a value is greater than a number.
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/rest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { rest } from "../index"

describe("rest", () => {
test("gets the rest item in an array", () => {
expect(rest([0, 1, 2, 3])).toEqual([1, 2, 3])
})
})
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const first = index(0)

export const last = <T>(items: T[]): T => items[items.length - 1]

export const rest = <T>([, ...remaining]: T[]) => remaining

export const constant = <T>(value: T) => () => value

export const identity = <T>(value: T) => value
Expand Down

0 comments on commit cd04181

Please sign in to comment.