Skip to content

Commit cf8b2dd

Browse files
KhraksMamtsovtim-smart
authored andcommittedFeb 14, 2025
Relax Trie variance (#4338)
1 parent 9c9654e commit cf8b2dd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
 

‎.changeset/pretty-trainers-rescue.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
`Trie<out A>` type annotations have been aligned. The type parameter was made covariant because the structure is immutable.

‎packages/effect/src/Trie.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type TypeId = typeof TypeId
3434
* @since 2.0.0
3535
* @category models
3636
*/
37-
export interface Trie<in out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
37+
export interface Trie<out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
3838
readonly [TypeId]: {
3939
readonly _Value: Covariant<Value>
4040
}
@@ -122,8 +122,8 @@ export const make: <Entries extends Array<readonly [string, any]>>(
122122
* @category mutations
123123
*/
124124
export const insert: {
125-
<V>(key: string, value: V): (self: Trie<V>) => Trie<V>
126-
<V>(self: Trie<V>, key: string, value: V): Trie<V>
125+
<V1>(key: string, value: V1): <V>(self: Trie<V>) => Trie<V | V1>
126+
<V1, V>(self: Trie<V>, key: string, value: V1): Trie<V | V1>
127127
} = TR.insert
128128

129129
/**
@@ -746,8 +746,8 @@ export const forEach: {
746746
* @category mutations
747747
*/
748748
export const modify: {
749-
<V>(key: string, f: (v: V) => V): (self: Trie<V>) => Trie<V>
750-
<V>(self: Trie<V>, key: string, f: (v: V) => V): Trie<V>
749+
<V1, V>(key: string, f: (v: V) => V1): (self: Trie<V>) => Trie<V1 | V>
750+
<V1, V>(self: Trie<V>, key: string, f: (v: V) => V1): Trie<V | V1>
751751
} = TR.modify
752752

753753
/**
@@ -807,6 +807,6 @@ export const removeMany: {
807807
* @category mutations
808808
*/
809809
export const insertMany: {
810-
<V>(iter: Iterable<[string, V]>): (self: Trie<V>) => Trie<V>
811-
<V>(self: Trie<V>, iter: Iterable<[string, V]>): Trie<V>
810+
<V1>(iter: Iterable<[string, V1]>): <V>(self: Trie<V>) => Trie<V | V1>
811+
<V1, V>(self: Trie<V>, iter: Iterable<[string, V1]>): Trie<V | V1>
812812
} = TR.insertMany

0 commit comments

Comments
 (0)
Please sign in to comment.