Skip to content

Commit

Permalink
Rename ReadonlyArray and ReadonlyRecord modules (#2529)
Browse files Browse the repository at this point in the history
  • Loading branch information
fubhy committed Apr 16, 2024
1 parent 5648339 commit 78b767c
Show file tree
Hide file tree
Showing 161 changed files with 2,020 additions and 1,995 deletions.
20 changes: 20 additions & 0 deletions .changeset/many-olives-sneeze.md
@@ -0,0 +1,20 @@
---
"@effect/typeclass": minor
"effect": minor
"@effect/platform-node-shared": patch
"@effect/sql-sqlite-node": patch
"@effect/opentelemetry": patch
"@effect/platform-node": patch
"@effect/experimental": patch
"@effect/platform-bun": patch
"@effect/printer-ansi": patch
"@effect/platform": patch
"@effect/rpc-http": patch
"@effect/printer": patch
"@effect/schema": patch
"@effect/cli": patch
"@effect/rpc": patch
"@effect/sql": patch
---

Renamed `ReadonlyArray` and `ReadonlyRecord` modules for better discoverability.
26 changes: 13 additions & 13 deletions packages/cli/README.md
Expand Up @@ -151,7 +151,7 @@ Let's continue with our `minigit` example and and create the `add` and `clone` s

```ts
import { Args, Command, Options } from "@effect/cli"
import { Console, Option, ReadonlyArray } from "effect"
import { Console, Option, Array } from "effect"

// minigit [--version] [-h | --help] [-c <name>=<value>]
const configs = Options.keyValueMap("c").pipe(Options.optional)
Expand All @@ -170,9 +170,9 @@ const minigit = Command.make("minigit", { configs }, ({ configs }) =>
const pathspec = Args.text({ name: "pathspec" }).pipe(Args.repeated)
const verbose = Options.boolean("verbose").pipe(Options.withAlias("v"))
const minigitAdd = Command.make("add", { pathspec, verbose }, ({ pathspec, verbose }) => {
const paths = ReadonlyArray.match(pathspec, {
const paths = Array.match(pathspec, {
onEmpty: () => "",
onNonEmpty: (paths) => ` ${ReadonlyArray.join(paths, " ")}`
onNonEmpty: (paths) => ` ${Array.join(paths, " ")}`
})
return Console.log(`Running 'minigit add${paths}' with '--verbose ${verbose}'`)
})
Expand All @@ -184,16 +184,16 @@ const depth = Options.integer('depth').pipe(Options.optional)
const minigitClone = Command.make("clone", { repository, directory, depth }, (config) => {
const depth = Option.map(config.depth, (depth) => `--depth ${depth}`)
const repository = Option.some(config.repository)
const optionsAndArgs = ReadonlyArray.getSomes([depth, repository, config.directory])
const optionsAndArgs = Array.getSomes([depth, repository, config.directory])
return Console.log(
"Running 'minigit clone' with the following options and arguments: " +
`'${ReadonlyArray.join(optionsAndArgs, ", ")}'`
`'${Array.join(optionsAndArgs, ", ")}'`
)
})
```

Some things to note in the above example:
1. We've additionally imported the `Args` module from `@effect/cli` and the `ReadonlyArray` module from `effect`
1. We've additionally imported the `Args` module from `@effect/cli` and the `Array` module from `effect`
2. We've used the `Args` module to specify some positional arguments for our `add` and `clone` subcommands
3. We've used `Options.withAlias` to give the `--verbose` flag an alias of `-v` for our `add` subcommand

Expand All @@ -209,7 +209,7 @@ Our final CLI application is as follows:
```ts
import { Args, Command, Options } from "@effect/cli"
import { NodeContext, NodeRuntime } from "@effect/platform-node"
import { Console, Effect, Option, ReadonlyArray } from "effect"
import { Console, Effect, Option, Array } from "effect"

// minigit [--version] [-h | --help] [-c <name>=<value>]
const configs = Options.keyValueMap("c").pipe(Options.optional)
Expand All @@ -228,9 +228,9 @@ const minigit = Command.make("minigit", { configs }, ({ configs }) =>
const pathspec = Args.text({ name: "pathspec" }).pipe(Args.repeated)
const verbose = Options.boolean("verbose").pipe(Options.withAlias("v"))
const minigitAdd = Command.make("add", { pathspec, verbose }, ({ pathspec, verbose }) => {
const paths = ReadonlyArray.match(pathspec, {
const paths = Array.match(pathspec, {
onEmpty: () => "",
onNonEmpty: (paths) => ` ${ReadonlyArray.join(paths, " ")}`
onNonEmpty: (paths) => ` ${Array.join(paths, " ")}`
})
return Console.log(`Running 'minigit add${paths}' with '--verbose ${verbose}'`)
})
Expand All @@ -242,10 +242,10 @@ const depth = Options.integer('depth').pipe(Options.optional)
const minigitClone = Command.make("clone", { repository, directory, depth }, (config) => {
const depth = Option.map(config.depth, (depth) => `--depth ${depth}`)
const repository = Option.some(config.repository)
const optionsAndArgs = ReadonlyArray.getSomes([depth, repository, config.directory])
const optionsAndArgs = Array.getSomes([depth, repository, config.directory])
return Console.log(
"Running 'minigit clone' with the following options and arguments: " +
`'${ReadonlyArray.join(optionsAndArgs, ", ")}'`
`'${Array.join(optionsAndArgs, ", ")}'`
)
})

Expand Down Expand Up @@ -380,14 +380,14 @@ const minigitClone = Command.make("clone", { repository, directory, depth }, (su
Effect.flatMap(minigit, (parentConfig) => {
const depth = Option.map(subcommandConfig.depth, (depth) => `--depth ${depth}`)
const repository = Option.some(subcommandConfig.repository)
const optionsAndArgs = ReadonlyArray.getSomes([depth, repository, subcommandConfig.directory])
const optionsAndArgs = Array.getSomes([depth, repository, subcommandConfig.directory])
const configs = Option.match(parentConfig.configs, {
onNone: () => "",
onSome: (map) => Array.from(map).map(([key, value]) => `${key}=${value}`).join(", ")
})
return Console.log(
"Running 'minigit clone' with the following options and arguments: " +
`'${ReadonlyArray.join(optionsAndArgs, ", ")}'\n` +
`'${Array.join(optionsAndArgs, ", ")}'\n` +
`and the following configuration parameters: ${configs}`
)
})
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/examples/minigit.ts
@@ -1,14 +1,14 @@
import { Args, Command, Options } from "@effect/cli"
import { NodeContext, NodeRuntime } from "@effect/platform-node"
import { Config, ConfigProvider, Console, Effect, Option, ReadonlyArray } from "effect"
import { Array, Config, ConfigProvider, Console, Effect, Option } from "effect"

// minigit [--version] [-h | --help] [-c <name>=<value>]
const configs = Options.keyValueMap("c").pipe(Options.optional)
const minigit = Command.make("minigit", { configs }, ({ configs }) =>
Option.match(configs, {
onNone: () => Console.log("Running 'minigit'"),
onSome: (configs) => {
const keyValuePairs = Array.from(configs)
const keyValuePairs = Array.fromIterable(configs)
.map(([key, value]) => `${key}=${value}`)
.join(", ")
return Console.log(`Running 'minigit' with the following configs: ${keyValuePairs}`)
Expand All @@ -22,9 +22,9 @@ const verbose = Options.boolean("verbose").pipe(
Options.withFallbackConfig(Config.boolean("VERBOSE"))
)
const minigitAdd = Command.make("add", { pathspec, verbose }, ({ pathspec, verbose }) => {
const paths = ReadonlyArray.match(pathspec, {
const paths = Array.match(pathspec, {
onEmpty: () => "",
onNonEmpty: (paths) => ` ${ReadonlyArray.join(paths, " ")}`
onNonEmpty: (paths) => ` ${Array.join(paths, " ")}`
})
return Console.log(`Running 'minigit add${paths}' with '--verbose ${verbose}'`)
})
Expand All @@ -43,14 +43,14 @@ const minigitClone = Command.make(
Effect.flatMap(minigit, (parentConfig) => {
const depth = Option.map(subcommandConfig.depth, (depth) => `--depth ${depth}`)
const repository = Option.some(subcommandConfig.repository)
const optionsAndArgs = ReadonlyArray.getSomes([depth, repository, subcommandConfig.directory])
const optionsAndArgs = Array.getSomes([depth, repository, subcommandConfig.directory])
const configs = Option.match(parentConfig.configs, {
onNone: () => "",
onSome: (map) => Array.from(map).map(([key, value]) => `${key}=${value}`).join(", ")
onSome: (map) => Array.fromIterable(map).map(([key, value]) => `${key}=${value}`).join(", ")
})
return Console.log(
"Running 'minigit clone' with the following options and arguments: " +
`'${ReadonlyArray.join(optionsAndArgs, ", ")}'\n` +
`'${Array.join(optionsAndArgs, ", ")}'\n` +
`and the following configuration parameters: ${configs}`
)
})
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/examples/naval-fate/store.ts
@@ -1,11 +1,11 @@
import * as KeyValueStore from "@effect/platform/KeyValueStore"
import * as Schema from "@effect/schema/Schema"
import * as Array from "effect/Array"
import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import { pipe } from "effect/Function"
import * as Layer from "effect/Layer"
import * as Option from "effect/Option"
import * as ReadonlyArray from "effect/ReadonlyArray"
import { CoordinatesOccupiedError, Mine, Ship, ShipExistsError, ShipNotFoundError } from "./domain.js"

/**
Expand Down Expand Up @@ -67,16 +67,16 @@ export const make = Effect.gen(function*($) {
return yield* $(Effect.fail(new ShipNotFoundError({ name, x, y })))
}
const shipAtCoords = pipe(
ReadonlyArray.fromIterable(oldShips.values()),
ReadonlyArray.findFirst((ship) => ship.hasCoordinates(x, y))
Array.fromIterable(oldShips.values()),
Array.findFirst((ship) => ship.hasCoordinates(x, y))
)
if (Option.isSome(shipAtCoords)) {
return yield* $(Effect.fail(
new CoordinatesOccupiedError({ name: shipAtCoords.value.name, x, y })
))
}
const mines = yield* $(getMines)
const mineAtCoords = ReadonlyArray.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
const mineAtCoords = Array.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
const ship = Option.isSome(mineAtCoords)
? foundShip.value.move(x, y).destroy()
: foundShip.value.move(x, y)
Expand All @@ -89,8 +89,8 @@ export const make = Effect.gen(function*($) {
Effect.gen(function*($) {
const oldShips = yield* $(getShips)
const shipAtCoords = pipe(
ReadonlyArray.fromIterable(oldShips.values()),
ReadonlyArray.findFirst((ship) => ship.hasCoordinates(x, y))
Array.fromIterable(oldShips.values()),
Array.findFirst((ship) => ship.hasCoordinates(x, y))
)
if (Option.isSome(shipAtCoords)) {
const ship = shipAtCoords.value.destroy()
Expand All @@ -102,20 +102,20 @@ export const make = Effect.gen(function*($) {
const setMine: NavalFateStore["setMine"] = (x, y) =>
Effect.gen(function*($) {
const mines = yield* $(getMines)
const mineAtCoords = ReadonlyArray.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
const mineAtCoords = Array.findFirst(mines, (mine) => mine.hasCoordinates(x, y))
if (Option.isNone(mineAtCoords)) {
const mine = Mine.create(x, y)
const newMines = ReadonlyArray.append(mines, mine)
const newMines = Array.append(mines, mine)
yield* $(setMines(newMines))
}
})

const removeMine: NavalFateStore["removeMine"] = (x, y) =>
Effect.gen(function*($) {
const mines = yield* $(getMines)
const mineAtCoords = ReadonlyArray.findFirstIndex(mines, (mine) => mine.hasCoordinates(x, y))
const mineAtCoords = Array.findFirstIndex(mines, (mine) => mine.hasCoordinates(x, y))
if (Option.isSome(mineAtCoords)) {
const newMines = ReadonlyArray.remove(mines, mineAtCoords.value)
const newMines = Array.remove(mines, mineAtCoords.value)
yield* $(setMines(newMines))
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Args.ts
Expand Up @@ -5,11 +5,11 @@ import type { FileSystem } from "@effect/platform/FileSystem"
import type { Path } from "@effect/platform/Path"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { Schema } from "@effect/schema/Schema"
import type { NonEmptyArray } from "effect/Array"
import type { Config } from "effect/Config"
import type { Effect } from "effect/Effect"
import type { Option } from "effect/Option"
import type { Pipeable } from "effect/Pipeable"
import type { NonEmptyArray } from "effect/ReadonlyArray"
import type { Secret } from "effect/Secret"
import type { CliConfig } from "./CliConfig.js"
import type { HelpDoc } from "./HelpDoc.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/CommandDescriptor.ts
Expand Up @@ -4,12 +4,12 @@
import type { FileSystem } from "@effect/platform/FileSystem"
import type { Path } from "@effect/platform/Path"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { NonEmptyReadonlyArray } from "effect/Array"
import type { Effect } from "effect/Effect"
import type { HashMap } from "effect/HashMap"
import type { HashSet } from "effect/HashSet"
import type { Option } from "effect/Option"
import type { Pipeable } from "effect/Pipeable"
import type { NonEmptyReadonlyArray } from "effect/ReadonlyArray"
import type { Args } from "./Args.js"
import type { CliConfig } from "./CliConfig.js"
import type { CommandDirective } from "./CommandDirective.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/HelpDoc.ts
Expand Up @@ -2,7 +2,7 @@
* @since 1.0.0
*/
import type { AnsiDoc } from "@effect/printer-ansi/AnsiDoc"
import type { NonEmptyReadonlyArray } from "effect/ReadonlyArray"
import type { NonEmptyReadonlyArray } from "effect/Array"
import type { Span } from "./HelpDoc/Span.js"
import * as InternalHelpDoc from "./internal/helpDoc.js"

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Options.ts
Expand Up @@ -5,13 +5,13 @@ import type { FileSystem } from "@effect/platform/FileSystem"
import type { Path } from "@effect/platform/Path"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { Schema } from "@effect/schema/Schema"
import type { NonEmptyArray } from "effect/Array"
import type { Config } from "effect/Config"
import type { Effect } from "effect/Effect"
import type { Either } from "effect/Either"
import type { HashMap } from "effect/HashMap"
import type { Option } from "effect/Option"
import type { Pipeable } from "effect/Pipeable"
import type { NonEmptyArray } from "effect/ReadonlyArray"
import type { Secret } from "effect/Secret"
import type { CliConfig } from "./CliConfig.js"
import type { HelpDoc } from "./HelpDoc.js"
Expand Down

0 comments on commit 78b767c

Please sign in to comment.