Skip to content

Commit

Permalink
replace use of unit terminology with void (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored and mikearnaldi committed Apr 16, 2024
1 parent 6460414 commit 5a2314b
Show file tree
Hide file tree
Showing 137 changed files with 772 additions and 700 deletions.
29 changes: 29 additions & 0 deletions .changeset/six-ears-beam.md
@@ -0,0 +1,29 @@
---
"@effect/platform-node-shared": minor
"@effect/platform-browser": minor
"@effect/opentelemetry": minor
"@effect/platform-node": minor
"@effect/experimental": minor
"@effect/platform-bun": minor
"@effect/typeclass": minor
"@effect/platform": minor
"effect": minor
"@effect/schema": minor
"@effect/cli": minor
"@effect/printer": minor
"@effect/printer-ansi": minor
"@effect/rpc": minor
"@effect/rpc-http": minor
"@effect/vitest": minor
---

replace use of `unit` terminology with `void`

For all the data types.

```ts
Effect.unit; // => Effect.void
Stream.unit; // => Stream.void

// etc
```
2 changes: 1 addition & 1 deletion packages/cli/src/internal/cliApp.ts
Expand Up @@ -252,7 +252,7 @@ const handleBuiltInOption = <R, E, A>(
)
return shouldRunCommand
? Console.log().pipe(Effect.zipRight(run(self, finalArgs, execute)))
: Effect.unit
: Effect.void
}))
),
Effect.catchAll((e) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/internal/options.ts
Expand Up @@ -1158,7 +1158,7 @@ const parseInternal = (
> => {
switch (self._tag) {
case "Empty": {
return Effect.unit
return Effect.void
}
case "Single": {
const singleNames = ReadonlyArray.filterMap(getNames(self), (name) => HashMap.get(args, name))
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/internal/primitive.ts
Expand Up @@ -483,7 +483,7 @@ const validatePathExistence = (
if (shouldPathExist === "yes" && !pathExists) {
return Effect.fail(`Path '${path}' must exist`)
}
return Effect.unit
return Effect.void
}

const validatePathType = (
Expand All @@ -499,7 +499,7 @@ const validatePathType = (
)
return Effect.fail(`Expected path '${path}' to be a regular file`).pipe(
Effect.unlessEffect(checkIsFile),
Effect.asUnit
Effect.asVoid
)
}
case "directory": {
Expand All @@ -509,11 +509,11 @@ const validatePathType = (
)
return Effect.fail(`Expected path '${path}' to be a directory`).pipe(
Effect.unlessEffect(checkIsDirectory),
Effect.asUnit
Effect.asVoid
)
}
case "either": {
return Effect.unit
return Effect.void
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions packages/cli/test/services/MockConsole.ts
Expand Up @@ -42,23 +42,23 @@ export const make = Effect.gen(function*(_) {
getLines,
log,
unsafe: globalThis.console,
assert: () => Effect.unit,
clear: Effect.unit,
count: () => Effect.unit,
countReset: () => Effect.unit,
debug: () => Effect.unit,
dir: () => Effect.unit,
dirxml: () => Effect.unit,
error: () => Effect.unit,
group: () => Effect.unit,
groupEnd: Effect.unit,
info: () => Effect.unit,
table: () => Effect.unit,
time: () => Effect.unit,
timeEnd: () => Effect.unit,
timeLog: () => Effect.unit,
trace: () => Effect.unit,
warn: () => Effect.unit
assert: () => Effect.void,
clear: Effect.void,
count: () => Effect.void,
countReset: () => Effect.void,
debug: () => Effect.void,
dir: () => Effect.void,
dirxml: () => Effect.void,
error: () => Effect.void,
group: () => Effect.void,
groupEnd: Effect.void,
info: () => Effect.void,
table: () => Effect.void,
time: () => Effect.void,
timeEnd: () => Effect.void,
timeLog: () => Effect.void,
trace: () => Effect.void,
warn: () => Effect.void
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/services/MockTerminal.ts
Expand Up @@ -47,15 +47,15 @@ export const make = Effect.gen(function*(_) {

const inputText: MockTerminal["inputText"] = (text: string) => {
const inputs = ReadonlyArray.map(text.split(""), (key) => toUserInput(key))
return Queue.offerAll(queue, inputs).pipe(Effect.asUnit)
return Queue.offerAll(queue, inputs).pipe(Effect.asVoid)
}

const inputKey: MockTerminal["inputKey"] = (
key: string,
modifiers?: Partial<MockTerminal.Modifiers>
) => {
const input = toUserInput(key, modifiers)
return Queue.offer(queue, input).pipe(Effect.asUnit)
return Queue.offer(queue, input).pipe(Effect.asVoid)
}

const display: MockTerminal["display"] = (input) => Console.log(input)
Expand Down
17 changes: 10 additions & 7 deletions packages/effect/src/Channel.ts
Expand Up @@ -236,9 +236,9 @@ export const as: {
* @since 2.0.0
* @category mapping
*/
export const asUnit: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
export const asVoid: <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
self: Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
) => Channel<OutElem, InElem, OutErr, InErr, void, InDone, Env> = channel.asUnit
) => Channel<OutElem, InElem, OutErr, InErr, void, InDone, Env> = channel.asVoid

/**
* Creates a channel backed by a buffer. When the buffer is empty, the channel
Expand Down Expand Up @@ -2049,11 +2049,14 @@ export const toStream: <OutElem, OutErr, OutDone, Env>(
self: Channel<Chunk.Chunk<OutElem>, unknown, OutErr, unknown, OutDone, unknown, Env>
) => Stream.Stream<OutElem, OutErr, Env> = stream.channelToStream

/**
* @since 2.0.0
* @category constructors
*/
export const unit: Channel<never> = core.unit
const void_: Channel<never> = core.void
export {
/**
* @since 2.0.0
* @category constructors
*/
void_ as void
}

/**
* Makes a channel from an effect that returns a channel in case of success.
Expand Down
15 changes: 9 additions & 6 deletions packages/effect/src/Effect.ts
Expand Up @@ -1466,11 +1466,14 @@ export const suspend: <A, E, R>(effect: LazyArg<Effect<A, E, R>>) => Effect<A, E
*/
export const sync: <A>(evaluate: LazyArg<A>) => Effect<A> = core.sync

/**
* @since 2.0.0
* @category constructors
*/
export const unit: Effect<void> = core.unit
const _void: Effect<void> = core.void
export {
/**
* @since 2.0.0
* @category constructors
*/
_void as void
}

/**
* @since 2.0.0
Expand Down Expand Up @@ -2103,7 +2106,7 @@ export const asSomeError: <A, E, R>(self: Effect<A, E, R>) => Effect<A, Option.O
* @since 2.0.0
* @category mapping
*/
export const asUnit: <A, E, R>(self: Effect<A, E, R>) => Effect<void, E, R> = core.asUnit
export const asVoid: <A, E, R>(self: Effect<A, E, R>) => Effect<void, E, R> = core.asVoid

/**
* Returns an effect that swaps the error/success cases. This allows you to
Expand Down
19 changes: 11 additions & 8 deletions packages/effect/src/Exit.ts
Expand Up @@ -127,7 +127,7 @@ export const as: {
* @since 2.0.0
* @category mapping
*/
export const asUnit: <A, E>(self: Exit<A, E>) => Exit<void, E> = core.exitAsUnit
export const asVoid: <A, E>(self: Exit<A, E>) => Exit<void, E> = core.exitAsVoid

/**
* Returns a `Some<Cause<E>>` if the specified exit is a `Failure`, `None`
Expand Down Expand Up @@ -357,13 +357,16 @@ export const matchEffect: {
*/
export const succeed: <A>(value: A) => Exit<A> = core.exitSucceed

/**
* Represents an `Exit` which succeeds with `undefined`.
*
* @since 2.0.0
* @category constructors
*/
export const unit: Exit<void> = core.exitUnit
const void_: Exit<void> = core.exitVoid
export {
/**
* Represents an `Exit` which succeeds with `undefined`.
*
* @since 2.0.0
* @category constructors
*/
void_ as void
}

/**
* Sequentially zips the this result with the specified result or else returns
Expand Down
17 changes: 10 additions & 7 deletions packages/effect/src/Fiber.ts
Expand Up @@ -602,13 +602,16 @@ export const status: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<FiberStat
*/
export const succeed: <A>(value: A) => Fiber<A> = internal.succeed

/**
* A fiber that has already succeeded with unit.
*
* @since 2.0.0
* @category constructors
*/
export const unit: Fiber<void> = internal.unit
const void_: Fiber<void> = internal.void
export {
/**
* A fiber that has already succeeded with unit.
*
* @since 2.0.0
* @category constructors
*/
void_ as void
}

/**
* Zips this fiber and the specified fiber together, producing a tuple of
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/FiberMap.ts
Expand Up @@ -280,7 +280,7 @@ export const remove: {
Effect.suspend(() => {
const fiber = MutableHashMap.get(self.backing, key)
if (fiber._tag === "None") {
return Effect.unit
return Effect.void
}
MutableHashMap.remove(self.backing, key)
return Fiber.interrupt(fiber.value)
Expand Down
13 changes: 8 additions & 5 deletions packages/effect/src/Option.ts
Expand Up @@ -629,12 +629,15 @@ export const as: {
* @category mapping
* @since 2.0.0
*/
export const asUnit: <_>(self: Option<_>) => Option<void> = as(undefined)
export const asVoid: <_>(self: Option<_>) => Option<void> = as(undefined)

/**
* @since 2.0.0
*/
export const unit: Option<void> = some(undefined)
const void_: Option<void> = some(undefined)
export {
/**
* @since 2.0.0
*/
void_ as void
}

/**
* Applies a function to the value of an `Option` and flattens the result, if the input is `Some`.
Expand Down
19 changes: 11 additions & 8 deletions packages/effect/src/STM.ts
Expand Up @@ -295,7 +295,7 @@ export const asSomeError: <A, E, R>(self: STM<A, E, R>) => STM<A, Option.Option<
* @since 2.0.0
* @category mapping
*/
export const asUnit: <A, E, R>(self: STM<A, E, R>) => STM<void, E, R> = stm.asUnit
export const asVoid: <A, E, R>(self: STM<A, E, R>) => STM<void, E, R> = stm.asVoid

/**
* Creates an `STM` value from a partial (but pure) function.
Expand Down Expand Up @@ -1860,13 +1860,16 @@ export const unlessSTM: {
*/
export const unsome: <A, E, R>(self: STM<A, Option.Option<E>, R>) => STM<Option.Option<A>, E, R> = stm.unsome

/**
* Returns an `STM` effect that succeeds with `Unit`.
*
* @since 2.0.0
* @category constructors
*/
export const unit: STM<void> = stm.unit
const void_: STM<void> = stm.void
export {
/**
* Returns an `STM` effect that succeeds with `void`.
*
* @since 2.0.0
* @category constructors
*/
void_ as void
}

/**
* Feeds elements of type `A` to `f` and accumulates all errors in error
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/Schedule.ts
Expand Up @@ -218,7 +218,7 @@ export const as: {
* @since 2.0.0
* @category constructors
*/
export const asUnit: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<void, In, R> = internal.asUnit
export const asVoid: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<void, In, R> = internal.asVoid

/**
* Returns a new schedule that has both the inputs and outputs of this and the
Expand Down
19 changes: 11 additions & 8 deletions packages/effect/src/Stream.ts
Expand Up @@ -3707,7 +3707,7 @@ export const throttleEffect: {
} = internal.throttleEffect

/**
* A stream that emits Unit values spaced by the specified duration.
* A stream that emits void values spaced by the specified duration.
*
* @since 2.0.0
* @category constructors
Expand Down Expand Up @@ -3915,13 +3915,16 @@ export const unfoldEffect: <S, A, E, R>(
f: (s: S) => Effect.Effect<Option.Option<readonly [A, S]>, E, R>
) => Stream<A, E, R> = internal.unfoldEffect

/**
* A stream that contains a single `Unit` value.
*
* @since 2.0.0
* @category constructors
*/
export const unit: Stream<void> = internal.unit
const void_: Stream<void> = internal.void
export {
/**
* A stream that contains a single `void` value.
*
* @since 2.0.0
* @category constructors
*/
void_ as void
}

/**
* Creates a stream produced from an `Effect`.
Expand Down
6 changes: 3 additions & 3 deletions packages/effect/src/TestClock.ts
Expand Up @@ -209,7 +209,7 @@ export class TestClockImpl implements TestClock {
core.flatMap((shouldAwait) =>
shouldAwait ?
pipe(this.warningStart(), core.zipRight(core.deferredAwait(deferred))) :
pipe(core.deferredSucceed(deferred, void 0), core.asUnit)
pipe(core.deferredSucceed(deferred, void 0), core.asVoid)
)
))
}
Expand Down Expand Up @@ -250,7 +250,7 @@ export class TestClockImpl implements TestClock {
}
/**
* Captures a "snapshot" of the identifier and status of all fibers in this
* test other than the current fiber. Fails with the `Unit` value if any of
* test other than the current fiber. Fails with the `void` value if any of
* these fibers are not done or suspended. Note that because we cannot
* synchronize on the status of multiple fibers at the same time this
* snapshot may not be fully consistent.
Expand Down Expand Up @@ -409,7 +409,7 @@ export class TestClockImpl implements TestClock {
core.flatMap((option) => {
switch (option._tag) {
case "None": {
return core.unit
return core.void
}
case "Some": {
const [end, deferred] = option.value
Expand Down

0 comments on commit 5a2314b

Please sign in to comment.