Skip to content

Commit

Permalink
Relax Trie variance (#4338)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhraksMamtsov authored and effect-bot committed Feb 6, 2025
1 parent 1ba4d89 commit 5a60d9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-trainers-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

`Trie<out A>` type annotations have been aligned. The type parameter was made covariant because the structure is immutable.
14 changes: 7 additions & 7 deletions packages/effect/src/Trie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type TypeId = typeof TypeId
* @since 2.0.0
* @category models
*/
export interface Trie<in out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
export interface Trie<out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
readonly [TypeId]: {
readonly _Value: Covariant<Value>
}
Expand Down Expand Up @@ -122,8 +122,8 @@ export const make: <Entries extends Array<readonly [string, any]>>(
* @category mutations
*/
export const insert: {
<V>(key: string, value: V): (self: Trie<V>) => Trie<V>
<V>(self: Trie<V>, key: string, value: V): Trie<V>
<V1>(key: string, value: V1): <V>(self: Trie<V>) => Trie<V | V1>
<V1, V>(self: Trie<V>, key: string, value: V1): Trie<V | V1>
} = TR.insert

/**
Expand Down Expand Up @@ -746,8 +746,8 @@ export const forEach: {
* @category mutations
*/
export const modify: {
<V>(key: string, f: (v: V) => V): (self: Trie<V>) => Trie<V>
<V>(self: Trie<V>, key: string, f: (v: V) => V): Trie<V>
<V1, V>(key: string, f: (v: V) => V1): (self: Trie<V>) => Trie<V1 | V>
<V1, V>(self: Trie<V>, key: string, f: (v: V) => V1): Trie<V | V1>
} = TR.modify

/**
Expand Down Expand Up @@ -807,6 +807,6 @@ export const removeMany: {
* @category mutations
*/
export const insertMany: {
<V>(iter: Iterable<[string, V]>): (self: Trie<V>) => Trie<V>
<V>(self: Trie<V>, iter: Iterable<[string, V]>): Trie<V>
<V1>(iter: Iterable<[string, V1]>): <V>(self: Trie<V>) => Trie<V | V1>
<V1, V>(self: Trie<V>, iter: Iterable<[string, V1]>): Trie<V | V1>
} = TR.insertMany

0 comments on commit 5a60d9f

Please sign in to comment.