Skip to content

Commit

Permalink
Add Array.tuple (Effect-TS#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikearnaldi authored Mar 31, 2023
1 parent 545287e commit 440ea09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-toys-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/data": patch
---

Add Array.tuple
11 changes: 11 additions & 0 deletions docs/modules/ReadonlyArray.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Added in v1.0.0
- [flap](#flap)
- [map](#map)
- [mapNonEmpty](#mapnonempty)
- [tuple](#tuple)
- [tupled](#tupled)
- [models](#models)
- [NonEmptyArray (type alias)](#nonemptyarray-type-alias)
Expand Down Expand Up @@ -1638,6 +1639,16 @@ export declare const mapNonEmpty: {
Added in v1.0.0
## tuple
**Signature**
```ts
export declare const tuple: <Args extends any[]>(...args: Args) => Args
```
Added in v1.0.0
## tupled
**Signature**
Expand Down
6 changes: 6 additions & 0 deletions src/ReadonlyArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,12 @@ export const Invariant: invariant.Invariant<ReadonlyArrayTypeLambda> = {
export const tupled: <A>(self: ReadonlyArray<A>) => Array<[A]> = invariant
.tupled(Invariant) as any

/**
* @category mapping
* @since 1.0.0
*/
export const tuple: <Args extends Array<any>>(...args: Args) => Args = (...args) => args

/**
* @category mapping
* @since 1.0.0
Expand Down
4 changes: 4 additions & 0 deletions test/ReadonlyArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,10 @@ describe.concurrent("ReadonlyArray", () => {
deepStrictEqual(S.combine([1, 2], [1, 2]), [1, 2])
})

it("tuple", () => {
deepStrictEqual(RA.tuple(0, 1, 2), [0, 1, 2])
})

it("empty", () => {
deepStrictEqual(RA.empty.length, 0)
})
Expand Down

0 comments on commit 440ea09

Please sign in to comment.