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

Function Chunk

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

Source from the content-addressed store, hash-verified

11444 * @since 3.10.0
11445 */
11446export function Chunk<Value extends Constraint>(value: Value): Chunk<Value> {
11447 const schema = declareConstructor<
11448 Chunk_.Chunk<Value["Type"]>,
11449 Chunk_.Chunk<Value["Encoded"]>,
11450 ChunkIso<Value>
11451 >()(
11452 [value],
11453 ([value]) => {
11454 const values = ArraySchema(value)
11455 return (input, ast, options) => {
11456 if (Chunk_.isChunk(input)) {
11457 return Effect.mapBothEager(
11458 SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
11459 {
11460 onSuccess: Chunk_.fromArrayUnsafe,
11461 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
11462 }
11463 )
11464 }
11465 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11466 }
11467 },
11468 {
11469 representation: {
11470 id: "effect/schema/Chunk",
11471 payload: null
11472 },
11473 expected: "Chunk",
11474 toCodec: ([value]) => chunkLink(ArraySchema(value)),
11475 toCodecArbitrary: ({ constraint, typeParameters: [value] }) =>
11476 chunkLink(
11477 withArrayLengthConstraints(
11478 ArraySchema(value),
11479 constraint?.minLength,
11480 constraint?.maxLength
11481 )
11482 ),
11483 toEquivalence: ([value]) => Chunk_.makeEquivalence(value)
11484 }
11485 )
11486 return make(schema.ast, { value })
11487}
11488
11489// -----------------------------------------------------------------------------
11490// DateTime schemas

Callers

nothing calls this directly

Calls 5

chunkLinkFunction · 0.85
declareConstructorFunction · 0.70
makeFunction · 0.70
failMethod · 0.65

Tested by

no test coverage detected