| 168 | } |
| 169 | |
| 170 | class ErrImpl<E> implements Result<never, E> { |
| 171 | #val: E; |
| 172 | constructor(val: E) { |
| 173 | this.#val = val; |
| 174 | } |
| 175 | |
| 176 | map<U>(_fn: (val: never) => U): Result<U, E> { |
| 177 | return this; |
| 178 | } |
| 179 | |
| 180 | mapErr<F>(fn: (val: E) => F): Result<never, F> { |
| 181 | return new ErrImpl(fn(this.#val)); |
| 182 | } |
| 183 | |
| 184 | mapOr<U>(fallback: U, _fn: (val: never) => U): U { |
| 185 | return fallback; |
| 186 | } |
| 187 | |
| 188 | mapOrElse<U>(fallback: () => U, _fn: (val: never) => U): U { |
| 189 | return fallback(); |
| 190 | } |
| 191 | |
| 192 | andThen<U>(_fn: (val: never) => Result<U, E>): Result<U, E> { |
| 193 | return this; |
| 194 | } |
| 195 | |
| 196 | and<U>(_res: Result<U, E>): Result<U, E> { |
| 197 | return this; |
| 198 | } |
| 199 | |
| 200 | or(res: Result<never, E>): Result<never, E> { |
| 201 | return res; |
| 202 | } |
| 203 | |
| 204 | orElse<F>(fn: (val: E) => ErrImpl<F>): Result<never, F> { |
| 205 | return fn(this.#val); |
| 206 | } |
| 207 | |
| 208 | isOk(): this is OkImpl<never> { |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | isErr(): this is ErrImpl<E> { |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | expect(msg: string): never { |
| 217 | throw new Error(`${msg}: ${this.#val}`); |
| 218 | } |
| 219 | |
| 220 | expectErr(_msg: string): E { |
| 221 | return this.#val; |
| 222 | } |
| 223 | |
| 224 | unwrap(): never { |
| 225 | if (this.#val instanceof Error) { |
| 226 | throw this.#val; |
| 227 | } |
nothing calls this directly
no outgoing calls
no test coverage detected