MCPcopy
hub / github.com/Effect-TS/effect / head

Function head

packages/effect/src/Schema.ts:6532–6548  ·  view source on GitHub ↗
(
  self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
)

Source from the content-addressed store, hash-verified

6530 * @since 3.10.0
6531 */
6532export function head<S extends Schema.Any, A extends ReadonlyArray<unknown>>(
6533 self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
6534): transform<S, OptionFromSelf<SchemaClass<A[number]>>> {
6535 return transform(
6536 self,
6537 OptionFromSelf(getNumberIndexedAccess(typeSchema(self))),
6538 {
6539 strict: false,
6540 decode: (i) => array_.head(i),
6541 encode: (a) =>
6542 option_.match(a, {
6543 onNone: () => [],
6544 onSome: array_.of
6545 })
6546 }
6547 )
6548}
6549
6550/**
6551 * Get the first element of a `NonEmptyReadonlyArray`.

Callers 1

Schema.tsFile · 0.70

Calls 5

typeSchemaFunction · 0.85
headMethod · 0.80
transformInterface · 0.70
OptionFromSelfFunction · 0.70
getNumberIndexedAccessFunction · 0.70

Tested by

no test coverage detected