Skip to content

Commit

Permalink
remove useless Readonly modifier in ReadonlyRecord module (Effect…
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Jun 2, 2023
1 parent 3bd2879 commit 41ffb28
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-pets-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/data": patch
---

remove useless `Readonly` modifier in `ReadonlyRecord` module
12 changes: 6 additions & 6 deletions docs/modules/ReadonlyRecord.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ Transforms the values of a `ReadonlyRecord` into an `Array` with a custom mappin
```ts
export declare const collect: {
<K extends string, A, B>(f: (key: K, a: A) => B): (self: Readonly<Record<K, A>>) => B[]
<K extends string, A, B>(self: Readonly<Record<K, A>>, f: (key: string, a: A) => B): B[]
<K extends string, A, B>(f: (key: K, a: A) => B): (self: Record<K, A>) => B[]
<K extends string, A, B>(self: Record<K, A>, f: (key: string, a: A) => B): B[]
}
```
Expand Down Expand Up @@ -180,7 +180,7 @@ Alias of {@link toEntries}.
**Signature**

```ts
export declare const toArray: <K extends string, A>(self: Readonly<Record<K, A>>) => [K, A][]
export declare const toArray: <K extends string, A>(self: Record<K, A>) => [K, A][]
```
**Example**
Expand All @@ -205,7 +205,7 @@ Takes a record and returns an array of tuples containing its keys and values.
**Signature**

```ts
export declare const toEntries: <K extends string, A>(self: Readonly<Record<K, A>>) => [K, A][]
export declare const toEntries: <K extends string, A>(self: Record<K, A>) => [K, A][]
```
**Example**
Expand Down Expand Up @@ -777,8 +777,8 @@ Maps a `ReadonlyRecord` into another `Record` by applying a transformation funct

```ts
export declare const map: {
<K extends string, A, B>(f: (a: A, key: K) => B): (self: Readonly<Record<K, A>>) => Record<K, B>
<K extends string, A, B>(self: Readonly<Record<K, A>>, f: (a: A, key: K) => B): Record<K, B>
<K extends string, A, B>(f: (a: A, key: K) => B): (self: Record<K, A>) => Record<K, B>
<K extends string, A, B>(self: Record<K, A>, f: (a: A, key: K) => B): Record<K, B>
}
```
Expand Down
49 changes: 41 additions & 8 deletions dtslint/ts4.9/ReadonlyRecord.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { pipe } from '@effect/data/Function'
import * as RR from '@effect/data/ReadonlyRecord'
import * as Brand from '@effect/data/Brand'
import * as E from '@effect/data/Either'

declare const r: Record<string, number>
declare const rr: Readonly<Record<string, number>>
declare const struct: Record<'a' | 'b', number>

//
// -------------------------------------------------------------------------------------
// map
//
// -------------------------------------------------------------------------------------

// $ExpectType Record<string, boolean>
RR.map(r, (
Expand All @@ -21,6 +23,18 @@ pipe(r, RR.map((
_key, // $ExpectType string
) => value > 0))

// $ExpectType Record<string, boolean>
RR.map(rr, (
value, // $ExpectType number
_key, // $ExpectType string
) => value > 0)

// $ExpectType Record<string, boolean>
pipe(rr, RR.map((
value, // $ExpectType number
_key, // $ExpectType string
) => value > 0))

// $ExpectType Record<"a" | "b", boolean>
RR.map(struct, (
value, // $ExpectType number
Expand All @@ -42,26 +56,26 @@ function mapToBoolean(): { [K in keyof typeof constStruct]: boolean } {
// $ExpectType { readonly a: boolean; readonly b: boolean; }
mapToBoolean()

//
// -------------------------------------------------------------------------------------
// get
//
// -------------------------------------------------------------------------------------

// $ExpectType Option<number>
pipe(r, RR.get('a'))

//
// -------------------------------------------------------------------------------------
// replaceOption
//
// -------------------------------------------------------------------------------------

// $ExpectType Option<Record<string, number>>
pipe(r, RR.replaceOption('a', 2))

// $ExpectType Option<Record<string, number | boolean>>
pipe(r, RR.replaceOption('a', true))

//
// -------------------------------------------------------------------------------------
// modifyOption
//
// -------------------------------------------------------------------------------------

// $ExpectType Option<Record<string, number>>
pipe(r, RR.modifyOption('a', () => 2))
Expand All @@ -86,3 +100,22 @@ declare const brandedRecord: Record<string & Brand.Brand<"brandedString">, numbe
// should support brands
// $ExpectType [string & Brand<"brandedString">, number][]
RR.toEntries(brandedRecord)

// -------------------------------------------------------------------------------------
// collect
// -------------------------------------------------------------------------------------

// $ExpectType Either<never, number>[]
RR.collect({ a: E.right(1), b: E.right(2), c: E.right(3) }, (_, n) => n)

// $ExpectType Either<never, number>[]
pipe({ a: E.right(1), b: E.right(2), c: E.right(3) }, RR.collect((_, n) => n))

// $ExpectType number[]
RR.collect(r, (_, a) => a)

// $ExpectType number[]
RR.collect(rr, (_, a) => a)

// $ExpectType number[]
RR.collect(struct, (_, a) => a)
4 changes: 2 additions & 2 deletions dtslint/ts4.9/Struct.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as S from '@effect/data/Struct'
import { pipe } from '@effect/data/Function'

// $ExpectType { a: boolean }
// $ExpectType { a: boolean; }
S.evolve({ a: 1 }, { a: x => x > 0 })

// $ExpectType { a: number, b: number }
// $ExpectType { a: number; b: number; }
pipe({ a: 'a', b: 2 }, S.evolve({ a: (s) => s.length }))
12 changes: 6 additions & 6 deletions src/ReadonlyRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export const fromEntries: <A>(self: Iterable<[string, A]>) => Record<string, A>
* @since 1.0.0
*/
export const collect: {
<K extends string, A, B>(f: (key: K, a: A) => B): (self: Readonly<Record<K, A>>) => Array<B>
<K extends string, A, B>(self: Readonly<Record<K, A>>, f: (key: string, a: A) => B): Array<B>
<K extends string, A, B>(f: (key: K, a: A) => B): (self: Record<K, A>) => Array<B>
<K extends string, A, B>(self: Record<K, A>, f: (key: string, a: A) => B): Array<B>
} = dual(
2,
<A, B>(self: ReadonlyRecord<A>, f: (key: string, a: A) => B): Array<B> => {
Expand All @@ -191,7 +191,7 @@ export const collect: {
* @category conversions
* @since 1.0.0
*/
export const toEntries: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = collect((
export const toEntries: <K extends string, A>(self: Record<K, A>) => Array<[K, A]> = collect((
key,
value
) => [key, value])
Expand All @@ -212,7 +212,7 @@ export const toEntries: <K extends string, A>(self: Readonly<Record<K, A>>) => A
* @category conversions
* @since 1.0.0
*/
export const toArray: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = toEntries
export const toArray: <K extends string, A>(self: Record<K, A>) => Array<[K, A]> = toEntries

// -------------------------------------------------------------------------------------
// utils
Expand Down Expand Up @@ -414,8 +414,8 @@ export const pop: {
* @since 1.0.0
*/
export const map: {
<K extends string, A, B>(f: (a: A, key: K) => B): (self: Readonly<Record<K, A>>) => Record<K, B>
<K extends string, A, B>(self: Readonly<Record<K, A>>, f: (a: A, key: K) => B): Record<K, B>
<K extends string, A, B>(f: (a: A, key: K) => B): (self: Record<K, A>) => Record<K, B>
<K extends string, A, B>(self: Record<K, A>, f: (a: A, key: K) => B): Record<K, B>
} = dual(
2,
<A, B>(self: ReadonlyRecord<A>, f: (a: A, key: string) => B): Record<string, B> => {
Expand Down
2 changes: 1 addition & 1 deletion src/Struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const evolve: {
const out = { ...obj }
for (const k in t) {
if (Object.prototype.hasOwnProperty.call(obj, k)) {
// @ts-ignore
// @ts-expect-error
out[k] = t[k](obj[k])
}
}
Expand Down

0 comments on commit 41ffb28

Please sign in to comment.