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

Release queue: minor #3620

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/chilled-hotels-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Adds HashMap.HashMap.Entry type helper
5 changes: 5 additions & 0 deletions .changeset/early-poems-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

`Latch` implements `Effect<void>` with `.await` semantic
5 changes: 5 additions & 0 deletions .changeset/fast-experts-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

fix Unify for Deferred
5 changes: 5 additions & 0 deletions .changeset/healthy-dogs-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Effect.mapAccum & Array.mapAccum preserve non-emptiness
5 changes: 5 additions & 0 deletions .changeset/lemon-worms-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

`Pool` is now a subtype of `Effect`, equivalent to `Pool.get`
5 changes: 5 additions & 0 deletions .changeset/purple-beans-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

support ManagedRuntime in Effect.provide
5 changes: 5 additions & 0 deletions .changeset/silly-glasses-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

move ManagedRuntime.TypeId to fix circular imports
5 changes: 5 additions & 0 deletions .changeset/smart-fishes-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

`ManagedRuntime<R, E>` is subtype of `Effect<Runtime<R>, E, never>`
5 changes: 5 additions & 0 deletions .changeset/tricky-oranges-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add an `isRegExp` type guard
6 changes: 6 additions & 0 deletions .changeset/wicked-bears-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"effect": minor
---

`Resource<A, E>` is subtype of `Effect<A, E>`.
`ScopedRed<A>` is subtype of `Effect<A>`.
21 changes: 21 additions & 0 deletions packages/effect/dtslint/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,3 +1504,24 @@ pipe(
_n // $ExpectType 1 | 2
) => "a" as const)
)

// -------------------------------------------------------------------------------------
// mapAccum
// -------------------------------------------------------------------------------------

// $ExpectType [state: number, mappedArray: string[]]
Array.mapAccum(strings, 0, (s, a, i) => [s + i, a])

// $ExpectType [state: number, mappedArray: [string, ...string[]]]
Array.mapAccum(nonEmptyReadonlyStrings, 0, (s, a, i) => [s + i, a])

// $ExpectType [state: number, mappedArray: string[]]
pipe(
strings,
Array.mapAccum(0, (s, a, i) => [s + i, a])
)
// $ExpectType [state: number, mappedArray: [string, ...string[]]]
pipe(
nonEmptyReadonlyStrings,
Array.mapAccum(0, (s, a, i) => [s + i, a])
)
25 changes: 25 additions & 0 deletions packages/effect/dtslint/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1263,3 +1263,28 @@ pipe(
) => "b" as const
)
)

// -------------------------------------------------------------------------------------
// mapAccum
// -------------------------------------------------------------------------------------

declare const nonEmptyReadonlyStrings: NonEmptyReadonlyArray<string>
declare const strings: Array<string>

// $ExpectType Effect<[number, string[]], never, never>
Effect.mapAccum(strings, 0, (s, a, i) => Effect.succeed([s + i, a]))

// $ExpectType Effect<[number, [string, ...string[]]], never, never>
Effect.mapAccum(nonEmptyReadonlyStrings, 0, (s, a, i) => Effect.succeed([s + i, a]))

// $ExpectType Effect<[number, string[]], never, never>
pipe(
strings,
Effect.mapAccum(0, (s, a, i) => Effect.succeed([s + i, a]))
)

// $ExpectType Effect<[number, [string, ...string[]]], never, never>
pipe(
nonEmptyReadonlyStrings,
Effect.mapAccum(0, (s, a, i) => Effect.succeed([s + i, a]))
)
10 changes: 9 additions & 1 deletion packages/effect/dtslint/HashMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pipe } from "effect/Function"
import { hole, pipe } from "effect/Function"
import * as HashMap from "effect/HashMap"
import * as Predicate from "effect/Predicate"
import type * as Types from "effect/Types"

declare const hmLiterals: HashMap.HashMap<"k", "v">
declare const numbers: HashMap.HashMap<string, number>
Expand All @@ -23,6 +24,13 @@ export type K = HashMap.HashMap.Key<typeof hmLiterals>
// $ExpectType "v"
export type V = HashMap.HashMap.Value<typeof hmLiterals>

// -------------------------------------------------------------------------------------
// HashMap.Entry
// -------------------------------------------------------------------------------------

// $ExpectType ["k", "v"]
hole<Types.Simplify<HashMap.HashMap.Entry<typeof hmLiterals>>>()

// -------------------------------------------------------------------------------------
// filter
// -------------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions packages/effect/dtslint/Predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ if (Predicate.isTupleOfAtLeast(unknowns, 3)) {
unknowns
}

// -------------------------------------------------------------------------------------
// isRegExp
// -------------------------------------------------------------------------------------

// $ExpectType RegExp[]
unknowns.filter(Predicate.isRegExp)

// -------------------------------------------------------------------------------------
// compose
// -------------------------------------------------------------------------------------
Expand Down
64 changes: 51 additions & 13 deletions packages/effect/dtslint/Unify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import * as Either from "effect/Either"
import type * as Exit from "effect/Exit"
import type * as Fiber from "effect/Fiber"
import type * as FiberRef from "effect/FiberRef"
import type * as ManagedRuntime from "effect/ManagedRuntime"
import type * as Micro from "effect/Micro"
import type * as Option from "effect/Option"
import type * as Pool from "effect/Pool"
import type * as Queue from "effect/Queue"
import type * as RcRef from "effect/RcRef"
import type * as Ref from "effect/Ref"
import type * as Resource from "effect/Resource"
import type * as ScopedRef from "effect/ScopedRef"
import type * as Stream from "effect/Stream"
import type * as SubscriptionRef from "effect/SubscriptionRef"
import type * as SynchronizedRef from "effect/SynchronizedRef"
Expand Down Expand Up @@ -98,7 +102,11 @@ export type RuntimeFiberUnify = Unify.Unify<
| Fiber.RuntimeFiber<1, 2>
| Fiber.RuntimeFiber<"a", "b">
>

// $ExpectType ManagedRuntime<1, 2> | ManagedRuntime<"a", "b">
export type ManagedRuntimeUnify = Unify.Unify<
| ManagedRuntime.ManagedRuntime<1, 2>
| ManagedRuntime.ManagedRuntime<"a", "b">
>
// $ExpectType Queue<1> | Queue<"a">
export type QueueUnify = Unify.Unify<
| Queue.Queue<1>
Expand All @@ -109,34 +117,64 @@ export type DequeueUnify = Unify.Unify<
| Queue.Dequeue<1>
| Queue.Dequeue<"a">
>
// $ExpectType Pool<1, 2> | Pool<"a", "b" | "c">
export type PoolUnify = Unify.Unify<
| Pool.Pool<1, 2>
| Pool.Pool<"a", "b">
| Pool.Pool<"a", "c">
>

// $ExpectType 0 | Option<string | number> | Ref<1> | SynchronizedRef<1> | SubscriptionRef<1> | Deferred<1, 2> | Deferred<"a", "b"> | Fiber<"a" | 1, "b" | 2> | RuntimeFiber<"a" | 1, "b" | 2> | Queue<1> | Queue<"a"> | Dequeue<"a" | 1> | Ref<"A"> | SynchronizedRef<"A"> | SubscriptionRef<"A"> | FiberRef<12> | FiberRef<"a2"> | Either<1 | "A", 0 | "E"> | Effect<1 | "A", 0 | "E", "R" | "R1"> | RcRef<1 | "A", 0 | "E">
// $ExpectType ScopedRef<1> | ScopedRef<"a">
export type ScopedRefUnify = Unify.Unify<
| ScopedRef.ScopedRef<1>
| ScopedRef.ScopedRef<"a">
>
// $ExpectType Resource<1, never> | Resource<never, 2> | Resource<1, 2> | Resource<"a", "b"> | Resource<any, any>
export type ResourceUnify = Unify.Unify<
| Resource.Resource<1>
| Resource.Resource<never, 2>
| Resource.Resource<1, 2>
| Resource.Resource<"a", "b">
| Resource.Resource<any, any>
>

// $ExpectType 0 | Option<string | number> | Ref<1> | Ref<"a"> | SynchronizedRef<1> | SynchronizedRef<"a"> | SubscriptionRef<1> | SubscriptionRef<"a"> | Deferred<"a", "b"> | FiberRef<1> | FiberRef<"a"> | ManagedRuntime<"a", "b"> | Queue<1> | Queue<"a"> | Dequeue<"a" | 1> | Pool<1, 2> | Pool<"a", "b" | "c"> | ScopedRef<1> | ScopedRef<"a"> | Resource<"a", "b"> | Deferred<1, 0> | Resource<1, 0> | Latch | ManagedRuntime<1, 0> | RcRef<"a" | 1, 0 | "b"> | Fiber<"a" | 1, 0 | "b"> | RuntimeFiber<"a" | 1, 0 | "b"> | Either<"a" | 1, 0 | "b"> | Effect<"a" | 1, 0 | "b", "R" | "R1">
export type AllUnify = Unify.Unify<
| Either.Either<1, 0>
| Either.Either<"A", "E">
| Either.Either<"a", "b">
| Option.Option<number>
| Option.Option<string>
| Effect.Effect<"A", "E", "R">
| Effect.Effect<"a", "b", "R">
| Effect.Effect<1, 0, "R1">
| Ref.Ref<1>
| Ref.Ref<"A">
| Ref.Ref<"a">
| SynchronizedRef.SynchronizedRef<1>
| SynchronizedRef.SynchronizedRef<"A">
| SynchronizedRef.SynchronizedRef<"a">
| SubscriptionRef.SubscriptionRef<1>
| SubscriptionRef.SubscriptionRef<"A">
| SubscriptionRef.SubscriptionRef<"a">
| RcRef.RcRef<1, 0>
| RcRef.RcRef<"A", "E">
| Deferred.Deferred<1, 2>
| RcRef.RcRef<"a", "b">
| Deferred.Deferred<1, 0>
| Deferred.Deferred<"a", "b">
| FiberRef.FiberRef<12>
| FiberRef.FiberRef<"a2">
| Fiber.Fiber<1, 2>
| FiberRef.FiberRef<1>
| FiberRef.FiberRef<"a">
| Fiber.Fiber<1, 0>
| Fiber.Fiber<"a", "b">
| Fiber.RuntimeFiber<1, 2>
| Fiber.RuntimeFiber<1, 0>
| Fiber.RuntimeFiber<"a", "b">
| Queue.Queue<1>
| Queue.Queue<"a">
| Queue.Dequeue<1>
| Queue.Dequeue<"a">
| Pool.Pool<1, 2>
| Pool.Pool<"a", "b">
| Pool.Pool<"a", "c">
| ScopedRef.ScopedRef<1>
| ScopedRef.ScopedRef<"a">
| Resource.Resource<1, 0>
| Resource.Resource<"a", "b">
| Effect.Latch
| ManagedRuntime.ManagedRuntime<1, 0>
| ManagedRuntime.ManagedRuntime<"a", "b">
| 0
>
12 changes: 8 additions & 4 deletions packages/effect/src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2859,11 +2859,15 @@ export const join: {
* @category folding
*/
export const mapAccum: {
<S, A, B>(
<S, A, B, I extends Iterable<A> = Iterable<A>>(
s: S,
f: (s: S, a: A, i: number) => readonly [S, B]
): (self: Iterable<A>) => [state: S, mappedArray: Array<B>]
<S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => readonly [S, B]): [state: S, mappedArray: Array<B>]
f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]
): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]
<S, A, B, I extends Iterable<A> = Iterable<A>>(
self: I,
s: S,
f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]
): [state: S, mappedArray: ReadonlyArray.With<I, B>]
} = dual(
3,
<S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/Deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface Deferred<in out A, in out E = never> extends Effect.Effect<A, E
* @since 3.8.0
*/
export interface DeferredUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
Deferred?: () => Extract<A[Unify.typeSymbol], Deferred<any>>
Deferred?: () => Extract<A[Unify.typeSymbol], Deferred<any, any>>
}

/**
Expand Down
44 changes: 36 additions & 8 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import * as _runtime from "./internal/runtime.js"
import * as _schedule from "./internal/schedule.js"
import type * as Layer from "./Layer.js"
import type { LogLevel } from "./LogLevel.js"
import type * as ManagedRuntime from "./ManagedRuntime.js"
import type * as Metric from "./Metric.js"
import type * as MetricLabel from "./MetricLabel.js"
import type * as Option from "./Option.js"
Expand Down Expand Up @@ -2364,15 +2365,15 @@ export const map: {
* @category mapping
*/
export const mapAccum: {
<S, A, B, E, R>(
<S, A, B, E, R, I extends Iterable<A> = Iterable<A>>(
zero: S,
f: (s: S, a: A, i: number) => Effect<readonly [S, B], E, R>
): (elements: Iterable<A>) => Effect<[S, Array<B>], E, R>
<A, S, B, E, R>(
elements: Iterable<A>,
f: (s: S, a: RA.ReadonlyArray.Infer<I>, i: number) => Effect<readonly [S, B], E, R>
): (elements: I) => Effect<[S, RA.ReadonlyArray.With<I, B>], E, R>
<A, S, B, E, R, I extends Iterable<A> = Iterable<A>>(
elements: I,
zero: S,
f: (s: S, a: A, i: number) => Effect<readonly [S, B], E, R>
): Effect<[S, Array<B>], E, R>
f: (s: S, a: RA.ReadonlyArray.Infer<I>, i: number) => Effect<readonly [S, B], E, R>
): Effect<[S, RA.ReadonlyArray.With<I, B>], E, R>
} = effect.mapAccum

/**
Expand Down Expand Up @@ -3330,12 +3331,19 @@ export const provide: {
): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E2 | E, RIn | Exclude<R, ROut>>
<R2>(context: Context.Context<R2>): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, R2>>
<R2>(runtime: Runtime.Runtime<R2>): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, R2>>
<E2, R2>(
managedRuntime: ManagedRuntime.ManagedRuntime<R2, E2>
): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E | E2, Exclude<R, R2>>
<A, E, R, ROut, E2, RIn>(
self: Effect<A, E, R>,
layer: Layer.Layer<ROut, E2, RIn>
): Effect<A, E | E2, RIn | Exclude<R, ROut>>
<A, E, R, R2>(self: Effect<A, E, R>, context: Context.Context<R2>): Effect<A, E, Exclude<R, R2>>
<A, E, R, R2>(self: Effect<A, E, R>, runtime: Runtime.Runtime<R2>): Effect<A, E, Exclude<R, R2>>
<A, E, E2, R, R2>(
self: Effect<A, E, R>,
runtime: ManagedRuntime.ManagedRuntime<R2, E2>
): Effect<A, E | E2, Exclude<R, R2>>
} = layer.effect_provide

/**
Expand Down Expand Up @@ -5408,7 +5416,7 @@ export const makeSemaphore: (permits: number) => Effect<Semaphore> = circular.ma
* @category latch
* @since 3.8.0
*/
export interface Latch {
export interface Latch extends Effect<void> {
/** open the latch, releasing all fibers waiting on it */
readonly open: Effect<void>
/** release all fibers waiting on the latch, without opening it */
Expand All @@ -5419,6 +5427,26 @@ export interface Latch {
readonly close: Effect<void>
/** only run the given effect when the latch is open */
readonly whenOpen: <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>

readonly [Unify.typeSymbol]?: unknown
readonly [Unify.unifySymbol]?: LatchUnify<this>
readonly [Unify.ignoreSymbol]?: LatchUnifyIgnore
}

/**
* @category models
* @since 3.8.0
*/
export interface LatchUnify<A extends { [Unify.typeSymbol]?: any }> extends EffectUnify<A> {
Latch?: () => Latch
}

/**
* @category models
* @since 3.8.0
*/
export interface LatchUnifyIgnore extends EffectUnifyIgnore {
Effect?: true
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/effect/src/HashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ export declare namespace HashMap {
* @category type-level
*/
export type Value<T extends HashMap<any, any>> = [T] extends [HashMap<infer _K, infer _V>] ? _V : never

/**
* This type-level utility extracts the entry type `[K, V]` from a `HashMap<K, V>` type.
*
* @example
* import { HashMap } from "effect"
*
* declare const hm: HashMap.HashMap<string, number>
*
* // $ExpectType [string, number]
* type V = HashMap.HashMap.Entry<typeof hm>
*
* @since 3.9.0
* @category type-level
*/
export type Entry<T extends HashMap<any, any>> = [Key<T>, Value<T>]
}

/**
Expand Down
Loading