MCPcopy Create free account
hub / github.com/Effect-TS/effect / Chunk

Function Chunk

packages/effect/src/Schema.ts:11537–11591  ·  view source on GitHub ↗
(value: Value)

Source from the content-addressed store, hash-verified

11535 * @since 3.10.0
11536 */
11537export function Chunk<Value extends Constraint>(value: Value): Chunk<Value> {
11538 const schema = declareConstructor<
11539 Chunk_.Chunk<Value["Type"]>,
11540 Chunk_.Chunk<Value["Encoded"]>,
11541 ChunkIso<Value>
11542 >()(
11543 [value],
11544 ([value]) => {
11545 const values = ArraySchema(value)
11546 return (input, ast, options) => {
11547 if (Chunk_.isChunk(input)) {
11548 return Effect.mapBothEager(
11549 SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
11550 {
11551 onSuccess: Chunk_.fromIterable,
11552 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
11553 }
11554 )
11555 }
11556 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11557 }
11558 },
11559 {
11560 representation: {
11561 id: "effect/schema/Chunk",
11562 payload: null
11563 },
11564 toCode: ({ typeParameters }) => ({
11565 runtime: `Schema.Chunk(${typeParameters[0].runtime})`,
11566 Type: `Chunk.Chunk<${typeParameters[0].Type}>`
11567 }),
11568 expected: "Chunk",
11569 toCodec: ([value]) =>
11570 link<Chunk_.Chunk<Value["Encoded"]>>()(
11571 ArraySchema(value),
11572 SchemaTransformation.transform({
11573 decode: Chunk_.fromIterable,
11574 encode: Arr.fromIterable
11575 })
11576 ),
11577 toArbitrary: ([value]) => (fc, ctx) =>
11578 collectionArbitrary(fc, ctx, value.arbitrary, value.terminal, Chunk_.fromIterable),
11579 toEquivalence: ([value]) => Chunk_.makeEquivalence(value),
11580 toFormatter: ([value]) => (t) => {
11581 const size = Chunk_.size(t)
11582 if (size === 0) {
11583 return "Chunk(0) {}"
11584 }
11585 const values = globalThis.Array.from(t).sort().map((v) => `${value(v)}`)
11586 return `Chunk(${size}) { ${values.join(", ")} }`
11587 }
11588 }
11589 )
11590 return make(schema.ast, { value })
11591}
11592
11593/**
11594 * Reviver for persisted {@link Chunk} declarations.

Callers 1

Schema.tsFile · 0.70

Calls 10

collectionArbitraryFunction · 0.85
joinMethod · 0.80
declareConstructorFunction · 0.70
linkFunction · 0.70
valueFunction · 0.70
makeFunction · 0.70
transformMethod · 0.65
sizeMethod · 0.65
failMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected