<A, B extends A>(refinement: (a: A) => a is B): (
self: TxChunk<A>
) => Effect.Effect<void>
<A>(predicate: (a: A) => boolean): (
self: TxChunk<A>
) => Effect.Effect<void>
<A, B extends A>(
self: TxChunk<A>,
refinement: (a: A) => a is B
): Effect.Effect<void>
<A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>Filters the TxChunk keeping only elements that satisfy the predicate.
Details
This function mutates the original TxChunk by removing elements that don't match the predicate. It does not return a new TxChunk reference.
Example (Filtering elements)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5, 6])
// Keep only even numbers atomically
yield* TxChunk.filter(txChunk, (n) => n % 2 === 0)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [2, 4, 6]
})export const const filter: {
<A, B extends A>(
refinement: (a: A) => a is B
): (self: TxChunk<A>) => Effect.Effect<void>
<A>(predicate: (a: A) => boolean): (
self: TxChunk<A>
) => Effect.Effect<void>
<A, B extends A>(
self: TxChunk<A>,
refinement: (a: A) => a is B
): Effect.Effect<void>
<A>(
self: TxChunk<A>,
predicate: (a: A) => boolean
): Effect.Effect<void>
}
Filters the TxChunk keeping only elements that satisfy the predicate.
Details
This function mutates the original TxChunk by removing elements that don't match the predicate. It
does not return a new TxChunk reference.
Example (Filtering elements)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5, 6])
// Keep only even numbers atomically
yield* TxChunk.filter(txChunk, (n) => n % 2 === 0)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [2, 4, 6]
})
filter: {
<function (type parameter) A in <A, B extends A>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect.Effect<void>A, function (type parameter) B in <A, B extends A>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect.Effect<void>B extends function (type parameter) A in <A, B extends A>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect.Effect<void>A>(refinement: (a: A) => a is Brefinement: (a: Aa: function (type parameter) A in <A, B extends A>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect.Effect<void>A) => a: Aa is function (type parameter) B in <A, B extends A>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect.Effect<void>B): (self: TxChunk<A>(parameter) self: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxChunk<in out A>TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM)
semantics for chunk operations.
Details
Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
calls Effect.txRetry and any of the accessed TxChunk values change.
Example (Using a transactional chunk)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create a transactional chunk
const txChunk: TxChunk.TxChunk<number> = yield* TxChunk.fromIterable([
1,
2,
3
])
// Single operations - no explicit transaction needed
yield* TxChunk.append(txChunk, 4)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
// Multi-step atomic operation - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.prepend(txChunk, 0)
yield* TxChunk.append(txChunk, 5)
})
)
const finalResult = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(finalResult)) // [0, 1, 2, 3, 4, 5]
})
TxChunk<function (type parameter) A in <A, B extends A>(refinement: (a: A) => a is B): (self: TxChunk<A>) => Effect.Effect<void>A>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) A in <A>(predicate: (a: A) => boolean): (self: TxChunk<A>) => Effect.Effect<void>A>(predicate: (a: A) => booleanpredicate: (a: Aa: function (type parameter) A in <A>(predicate: (a: A) => boolean): (self: TxChunk<A>) => Effect.Effect<void>A) => boolean): (self: TxChunk<A>(parameter) self: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxChunk<in out A>TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM)
semantics for chunk operations.
Details
Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
calls Effect.txRetry and any of the accessed TxChunk values change.
Example (Using a transactional chunk)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create a transactional chunk
const txChunk: TxChunk.TxChunk<number> = yield* TxChunk.fromIterable([
1,
2,
3
])
// Single operations - no explicit transaction needed
yield* TxChunk.append(txChunk, 4)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
// Multi-step atomic operation - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.prepend(txChunk, 0)
yield* TxChunk.append(txChunk, 5)
})
)
const finalResult = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(finalResult)) // [0, 1, 2, 3, 4, 5]
})
TxChunk<function (type parameter) A in <A>(predicate: (a: A) => boolean): (self: TxChunk<A>) => Effect.Effect<void>A>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) A in <A, B extends A>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect.Effect<void>A, function (type parameter) B in <A, B extends A>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect.Effect<void>B extends function (type parameter) A in <A, B extends A>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect.Effect<void>A>(self: TxChunk<A>(parameter) self: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxChunk<in out A>TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM)
semantics for chunk operations.
Details
Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
calls Effect.txRetry and any of the accessed TxChunk values change.
Example (Using a transactional chunk)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create a transactional chunk
const txChunk: TxChunk.TxChunk<number> = yield* TxChunk.fromIterable([
1,
2,
3
])
// Single operations - no explicit transaction needed
yield* TxChunk.append(txChunk, 4)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
// Multi-step atomic operation - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.prepend(txChunk, 0)
yield* TxChunk.append(txChunk, 5)
})
)
const finalResult = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(finalResult)) // [0, 1, 2, 3, 4, 5]
})
TxChunk<function (type parameter) A in <A, B extends A>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect.Effect<void>A>, refinement: (a: A) => a is Brefinement: (a: Aa: function (type parameter) A in <A, B extends A>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect.Effect<void>A) => a: Aa is function (type parameter) B in <A, B extends A>(self: TxChunk<A>, refinement: (a: A) => a is B): Effect.Effect<void>B): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) A in <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>A>(self: TxChunk<A>(parameter) self: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxChunk<in out A>TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM)
semantics for chunk operations.
Details
Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
calls Effect.txRetry and any of the accessed TxChunk values change.
Example (Using a transactional chunk)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create a transactional chunk
const txChunk: TxChunk.TxChunk<number> = yield* TxChunk.fromIterable([
1,
2,
3
])
// Single operations - no explicit transaction needed
yield* TxChunk.append(txChunk, 4)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
// Multi-step atomic operation - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.prepend(txChunk, 0)
yield* TxChunk.append(txChunk, 5)
})
)
const finalResult = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(finalResult)) // [0, 1, 2, 3, 4, 5]
})
TxChunk<function (type parameter) A in <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>A>, predicate: (a: A) => booleanpredicate: (a: Aa: function (type parameter) A in <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>A) => boolean): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
} = import dualdual(
2,
<function (type parameter) A in <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>A>(self: TxChunk<A>(parameter) self: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxChunk<in out A>TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM)
semantics for chunk operations.
Details
Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
calls Effect.txRetry and any of the accessed TxChunk values change.
Example (Using a transactional chunk)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create a transactional chunk
const txChunk: TxChunk.TxChunk<number> = yield* TxChunk.fromIterable([
1,
2,
3
])
// Single operations - no explicit transaction needed
yield* TxChunk.append(txChunk, 4)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
// Multi-step atomic operation - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.prepend(txChunk, 0)
yield* TxChunk.append(txChunk, 5)
})
)
const finalResult = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(finalResult)) // [0, 1, 2, 3, 4, 5]
})
TxChunk<function (type parameter) A in <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>A>, predicate: (a: A) => booleanpredicate: (a: Aa: function (type parameter) A in <A>(self: TxChunk<A>, predicate: (a: A) => boolean): Effect.Effect<void>A) => boolean): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void> =>
const update: {
<A>(
f: (
current: Chunk.Chunk<NoInfer<A>>
) => Chunk.Chunk<A>
): (self: TxChunk<A>) => Effect.Effect<void>
<A>(
self: TxChunk<A>,
f: (current: Chunk.Chunk<A>) => Chunk.Chunk<A>
): Effect.Effect<void>
}
update(self: TxChunk<A>(parameter) self: {
ref: TxRef.TxRef<Chunk.Chunk<A>>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self, (current: Chunk.Chunk<A>(parameter) current: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
current) => import ChunkChunk.filter(current: Chunk.Chunk<A>(parameter) current: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
current, predicate: (a: A) => booleanpredicate))
)