MCPcopy Index your code
hub / github.com/Effect-TS/effect / single

Function single

packages/sql/src/SqlSchema.ts:82–97  ·  view source on GitHub ↗
(
  options: {
    readonly Request: Schema.Schema<IA, II, IR>
    readonly Result: Schema.Schema<A, AI, AR>
    readonly execute: (request: II) => Effect.Effect<ReadonlyArray<unknown>, E, R>
  }
)

Source from the content-addressed store, hash-verified

80 * @category constructor
81 */
82export const single = <IR, II, IA, AR, AI, A, R, E>(
83 options: {
84 readonly Request: Schema.Schema<IA, II, IR>
85 readonly Result: Schema.Schema<A, AI, AR>
86 readonly execute: (request: II) => Effect.Effect<ReadonlyArray<unknown>, E, R>
87 }
88) => {
89 const encodeRequest = Schema.encode(options.Request)
90 const decode = Schema.decodeUnknown(options.Result)
91 return (request: IA): Effect.Effect<A, E | ParseError | Cause.NoSuchElementException, R | IR | AR> =>
92 Effect.flatMap(
93 Effect.flatMap(encodeRequest(request), options.execute),
94 (arr): Effect.Effect<A, ParseError | Cause.NoSuchElementException, AR> =>
95 Array.isArray(arr) && arr.length > 0 ? decode(arr[0]) : Effect.fail(new Cause.NoSuchElementException())
96 )
97}

Callers

nothing calls this directly

Calls 3

encodeMethod · 0.80
decodeFunction · 0.70
failMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…