MCPcopy
hub / github.com/facebook/react / OkImpl

Class OkImpl

compiler/packages/babel-plugin-react-compiler/src/Utils/Result.ts:92–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92class OkImpl<T> implements Result<T, never> {
93 #val: T;
94 constructor(val: T) {
95 this.#val = val;
96 }
97
98 map<U>(fn: (val: T) => U): Result<U, never> {
99 return new OkImpl(fn(this.#val));
100 }
101
102 mapErr<F>(_fn: (val: never) => F): Result<T, F> {
103 return this;
104 }
105
106 mapOr<U>(_fallback: U, fn: (val: T) => U): U {
107 return fn(this.#val);
108 }
109
110 mapOrElse<U>(_fallback: () => U, fn: (val: T) => U): U {
111 return fn(this.#val);
112 }
113
114 andThen<U>(fn: (val: T) => Result<U, never>): Result<U, never> {
115 return fn(this.#val);
116 }
117
118 and<U>(res: Result<U, never>): Result<U, never> {
119 return res;
120 }
121
122 or(_res: Result<T, never>): Result<T, never> {
123 return this;
124 }
125
126 orElse<F>(_fn: (val: never) => Result<T, F>): Result<T, F> {
127 return this;
128 }
129
130 isOk(): this is OkImpl<T> {
131 return true;
132 }
133
134 isErr(): this is ErrImpl<never> {
135 return false;
136 }
137
138 expect(_msg: string): T {
139 return this.#val;
140 }
141
142 expectErr(msg: string): never {
143 throw new Error(`${msg}: ${this.#val}`);
144 }
145
146 unwrap(): T {
147 return this.#val;
148 }
149

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected