Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusted various function signatures to return Array #3340

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/wet-laws-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@effect/platform": patch
"effect": minor
"@effect/cli": patch
"@effect/rpc": patch
---

Changed various function signatures to return `Array` instead of `ReadonlyArray`
2 changes: 1 addition & 1 deletion packages/cli/src/internal/commandDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ const parseInternal = (
case "Standard": {
const parseCommandLine = (
args: ReadonlyArray<string>
): Effect.Effect<ReadonlyArray<string>, ValidationError.ValidationError> =>
): Effect.Effect<Array<string>, ValidationError.ValidationError> =>
Arr.matchLeft(args, {
onEmpty: () => {
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export declare namespace ConfigProvider {
path: ReadonlyArray<string>,
config: Config.Config.Primitive<A>,
split?: boolean
): Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
): Effect.Effect<Array<A>, ConfigError.ConfigError>
enumerateChildren(
path: ReadonlyArray<string>
): Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError>
Expand Down Expand Up @@ -162,7 +162,7 @@ export const makeFlat: (options: {
path: ReadonlyArray<string>,
config: Config.Config.Primitive<A>,
split: boolean
) => Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) => Effect.Effect<Array<A>, ConfigError.ConfigError>
readonly enumerateChildren: (
path: ReadonlyArray<string>
) => Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError>
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export const set: {
* @since 2.0.0
* @category getters
*/
export const snapshot: Effect.Effect<ReadonlyArray<MetricPair.MetricPair.Untyped>> = internal.snapshot
export const snapshot: Effect.Effect<Array<MetricPair.MetricPair.Untyped>> = internal.snapshot

/**
* Creates a metric that ignores input and produces constant output.
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/MetricRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type MetricRegistryTypeId = typeof MetricRegistryTypeId
*/
export interface MetricRegistry {
readonly [MetricRegistryTypeId]: MetricRegistryTypeId
snapshot(): ReadonlyArray<MetricPair.MetricPair.Untyped>
snapshot(): Array<MetricPair.MetricPair.Untyped>
get<Type extends MetricKeyType.MetricKeyType<any, any>>(
key: MetricKey.MetricKey<Type>
): MetricHook.MetricHook<
Expand Down
40 changes: 20 additions & 20 deletions packages/effect/src/internal/configProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const makeFlat = (
path: ReadonlyArray<string>,
config: Config.Config.Primitive<A>,
split: boolean
) => Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) => Effect.Effect<Array<A>, ConfigError.ConfigError>
readonly enumerateChildren: (
path: ReadonlyArray<string>
) => Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError>
Expand Down Expand Up @@ -114,7 +114,7 @@ export const fromEnv = (
path: ReadonlyArray<string>,
primitive: Config.Config.Primitive<A>,
split = true
): Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError> => {
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
const pathString = makePathString(path)
const current = getEnv()
const valueOpt = pathString in current ? Option.some(current[pathString]!) : Option.none()
Expand Down Expand Up @@ -165,7 +165,7 @@ export const fromMap = (
path: ReadonlyArray<string>,
primitive: Config.Config.Primitive<A>,
split = true
): Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError> => {
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
const pathString = makePathString(path)
const valueOpt = mapWithIndexSplit.has(pathString) ?
Option.some(mapWithIndexSplit.get(pathString)!) :
Expand Down Expand Up @@ -240,20 +240,20 @@ const fromFlatLoop = <A>(
prefix: ReadonlyArray<string>,
config: Config.Config<A>,
split: boolean
): Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError> => {
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
const op = config as _config.ConfigPrimitive
switch (op._tag) {
case OpCodes.OP_CONSTANT: {
return core.succeed(Arr.of(op.value)) as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
return core.succeed(Arr.of(op.value)) as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_DESCRIBED: {
return core.suspend(
() => fromFlatLoop(flat, prefix, op.config, split)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_FAIL: {
return core.fail(configError.MissingData(prefix, op.message)) as Effect.Effect<
ReadonlyArray<A>,
Array<A>,
ConfigError.ConfigError
>
}
Expand All @@ -269,11 +269,11 @@ const fromFlatLoop = <A>(
}
return core.fail(error1)
})
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_LAZY: {
return core.suspend(() => fromFlatLoop(flat, prefix, op.config(), split)) as Effect.Effect<
ReadonlyArray<A>,
Array<A>,
ConfigError.ConfigError
>
}
Expand All @@ -290,7 +290,7 @@ const fromFlatLoop = <A>(
)
)
)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_NESTED: {
return core.suspend(() =>
Expand All @@ -300,7 +300,7 @@ const fromFlatLoop = <A>(
op.config,
split
)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_PRIMITIVE: {
return pipe(
Expand All @@ -317,7 +317,7 @@ const fromFlatLoop = <A>(
})
)
)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_SEQUENCE: {
return pipe(
Expand All @@ -330,7 +330,7 @@ const fromFlatLoop = <A>(
if (indices.length === 0) {
return core.suspend(() =>
core.map(fromFlatLoop(flat, patchedPrefix, op.config, true), Arr.of)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
return pipe(
core.forEachSequential(
Expand All @@ -344,7 +344,7 @@ const fromFlatLoop = <A>(
}
return Arr.of(flattened)
})
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
})
)
)
Expand Down Expand Up @@ -382,7 +382,7 @@ const fromFlatLoop = <A>(
)
)
)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
case OpCodes.OP_ZIP_WITH: {
return core.suspend(() =>
Expand Down Expand Up @@ -430,7 +430,7 @@ const fromFlatLoop = <A>(
)
)
)
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
) as unknown as Effect.Effect<Array<A>, ConfigError.ConfigError>
}
}
}
Expand Down Expand Up @@ -592,7 +592,7 @@ export const within = dual<
return orElse(nest, () => self)
})

const splitPathString = (text: string, delim: string): ReadonlyArray<string> => {
const splitPathString = (text: string, delim: string): Array<string> => {
const split = text.split(new RegExp(`\\s*${regexp.escape(delim)}\\s*`))
return split
}
Expand All @@ -603,7 +603,7 @@ const parsePrimitive = <A>(
primitive: Config.Config.Primitive<A>,
delimiter: string,
split: boolean
): Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError> => {
): Effect.Effect<Array<A>, ConfigError.ConfigError> => {
if (!split) {
return pipe(
primitive.parse(text),
Expand All @@ -620,11 +620,11 @@ const parsePrimitive = <A>(
)
}

const transpose = <A>(array: ReadonlyArray<ReadonlyArray<A>>): ReadonlyArray<ReadonlyArray<A>> => {
const transpose = <A>(array: ReadonlyArray<ReadonlyArray<A>>): Array<Array<A>> => {
return Object.keys(array[0]).map((column) => array.map((row) => row[column as any]))
}

const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<ReadonlyArray<number>> =>
const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<Array<number>> =>
pipe(
core.forEachSequential(quotedIndices, parseQuotedIndex),
core.mapBoth({
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/internal/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ export const zip = dual<
)

/** @internal */
export const unsafeSnapshot = (): ReadonlyArray<MetricPair.MetricPair.Untyped> => globalMetricRegistry.snapshot()
export const unsafeSnapshot = (): Array<MetricPair.MetricPair.Untyped> => globalMetricRegistry.snapshot()

/** @internal */
export const snapshot: Effect.Effect<ReadonlyArray<MetricPair.MetricPair.Untyped>> = core.sync(
export const snapshot: Effect.Effect<Array<MetricPair.MetricPair.Untyped>> = core.sync(
unsafeSnapshot
)
2 changes: 1 addition & 1 deletion packages/effect/src/internal/metric/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MetricRegistryImpl implements MetricRegistry.MetricRegistry {
MetricHook.MetricHook.Root
>()

snapshot(): ReadonlyArray<MetricPair.MetricPair.Untyped> {
snapshot(): Array<MetricPair.MetricPair.Untyped> {
const result: Array<MetricPair.MetricPair.Untyped> = []
for (const [key, hook] of this.map) {
result.push(metricPair.unsafeMake(key, hook.get()))
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Here's a list of operations that can be performed using the `FileSystem` tag:
| **makeTempFile** | `options?: MakeTempFileOptions` | `Effect<string, PlatformError>` | Create a temporary file. The directory creation is functionally equivalent to `makeTempDirectory`. The file name will be a randomly generated string. |
| **makeTempFileScoped** | `options?: MakeTempFileOptions` | `Effect<string, PlatformError, Scope>` | Create a temporary file inside a scope. Functionally equivalent to `makeTempFile`, but the file will be automatically deleted when the scope is closed. |
| **open** | `path: string`, `options?: OpenFileOptions` | `Effect<File, PlatformError, Scope>` | Open a file at `path` with the specified `options`. The file handle will be automatically closed when the scope is closed. |
| **readDirectory** | `path: string`, `options?: ReadDirectoryOptions` | `Effect<ReadonlyArray<string>, PlatformError>` | List the contents of a directory. You can recursively list the contents of nested directories by setting the `recursive` option. |
| **readDirectory** | `path: string`, `options?: ReadDirectoryOptions` | `Effect<Array<string>, PlatformError>` | List the contents of a directory. You can recursively list the contents of nested directories by setting the `recursive` option. |
| **readFile** | `path: string` | `Effect<Uint8Array, PlatformError>` | Read the contents of a file. |
| **readFileString** | `path: string`, `encoding?: string` | `Effect<string, PlatformError>` | Read the contents of a file as a string. |
| **readLink** | `path: string` | `Effect<string, PlatformError>` | Read the destination of a symbolic link. |
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const flatten: (self: Command) => NonEmptyReadonlyArray<StandardCommand>
export const lines: (
command: Command,
encoding?: string
) => Effect<ReadonlyArray<string>, PlatformError, CommandExecutor> = internal.lines
) => Effect<Array<string>, PlatformError, CommandExecutor> = internal.lines

/**
* Create a command with the specified process name and an optional list of
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/CommandExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface CommandExecutor {
*
* If an encoding is not specified, the encoding will default to `utf-8`.
*/
readonly lines: (command: Command, encoding?: string) => Effect<ReadonlyArray<string>, PlatformError>
readonly lines: (command: Command, encoding?: string) => Effect<Array<string>, PlatformError>
/**
* Runs the command returning the output as a `Stream`.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface FileSystem {
readonly readDirectory: (
path: string,
options?: ReadDirectoryOptions
) => Effect.Effect<ReadonlyArray<string>, PlatformError>
) => Effect.Effect<Array<string>, PlatformError>
/**
* Read the contents of a file.
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/platform/src/Transferable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import * as Option from "effect/Option"
export interface CollectorService {
readonly addAll: (_: Iterable<globalThis.Transferable>) => Effect.Effect<void>
readonly unsafeAddAll: (_: Iterable<globalThis.Transferable>) => void
readonly read: Effect.Effect<ReadonlyArray<globalThis.Transferable>>
readonly unsafeRead: () => ReadonlyArray<globalThis.Transferable>
readonly read: Effect.Effect<Array<globalThis.Transferable>>
readonly unsafeRead: () => Array<globalThis.Transferable>
readonly unsafeClear: () => void
readonly clear: Effect.Effect<void>
}
Expand All @@ -41,7 +41,7 @@ export const unsafeMakeCollector = (): CollectorService => {
tranferables.push(transfer)
}
}
const unsafeRead = (): ReadonlyArray<globalThis.Transferable> => tranferables
const unsafeRead = (): Array<globalThis.Transferable> => tranferables
const unsafeClear = (): void => {
tranferables.length = 0
}
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/internal/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const runInShell = dual<
export const lines = (
command: Command.Command,
encoding = "utf-8"
): Effect.Effect<ReadonlyArray<string>, PlatformError, CommandExecutor.CommandExecutor> =>
): Effect.Effect<Array<string>, PlatformError, CommandExecutor.CommandExecutor> =>
Effect.flatMap(commandExecutor.CommandExecutor, (executor) => executor.lines(command, encoding))

const Proto = {
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/internal/commandExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const makeExecutor = (start: _CommandExecutor.CommandExecutor["start"]):
return pipe(
streamLines(command, encoding),
Stream.runCollect,
Effect.map(Chunk.toReadonlyArray)
Effect.map(Chunk.toArray)
)
},
streamLines
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const toHandlerEffect = <R extends Router<any, any>>(router: R, options?:
const getEncode = withRequestTag((req) => Schema.encode(Serializable.exitSchema(req)))
const getEncodeChunk = withRequestTag((req) => Schema.encode(Schema.Chunk(Serializable.exitSchema(req))))

return (u: unknown): Effect.Effect<ReadonlyArray<Router.ResponseEffect>, ParseError, Router.Context<R>> =>
return (u: unknown): Effect.Effect<Array<Router.ResponseEffect>, ParseError, Router.Context<R>> =>
Effect.flatMap(
decode(u),
Effect.forEach((req): Effect.Effect<Router.ResponseEffect, ParseError, any> => {
Expand Down