216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376 | @final
@frozen()
class Left(EitherProtocol[L, Never]):
"""[`Left[L]`][wraps.either.Left] variant of [`Either[L, R]`][wraps.either.Either]."""
value: L
def __repr__(self) -> str:
return wrap_repr(self, self.value)
@classmethod
def create(cls, value: M) -> Left[M]:
return cls(value) # type: ignore[arg-type, return-value]
def is_left(self) -> Literal[True]:
return True
def is_left_and(self, predicate: Predicate[L]) -> bool:
return predicate(self.value)
async def is_left_and_await(self, predicate: AsyncPredicate[L]) -> bool:
return await predicate(self.value)
def is_right(self) -> Literal[False]:
return False
def is_right_and(self, predicate: Predicate[R]) -> Literal[False]:
return False
async def is_right_and_await(self, predicate: AsyncPredicate[R]) -> Literal[False]:
return False
def left(self) -> Some[L]:
return Some(self.value)
def left_or(self, default: L) -> L: # type: ignore[misc]
return self.value
def left_or_else(self, default: Nullary[L]) -> L:
return self.value
async def left_or_else_await(self, default: AsyncNullary[L]) -> L:
return self.value
def right(self) -> Null:
return NULL
def right_or(self, default: R) -> R: # type: ignore[misc]
return default
def right_or_else(self, default: Nullary[R]) -> R:
return default()
async def right_or_else_await(self, default: AsyncNullary[R]) -> R:
return await default()
def expect_left(self, message: str) -> L:
return self.value
def expect_right(self, message: str) -> Never:
panic(message)
def unwrap_left(self) -> L:
return self.value
def unwrap_right(self) -> Never:
panic(UNWRAP_RIGHT_ON_LEFT)
def into_either(self: Left[T]) -> T:
return self.value
def inspect_left(self, function: Inspect[L]) -> Left[L]:
function(self.value)
return self
def inspect_right(self, function: Inspect[R]) -> Left[L]:
return self
async def inspect_left_await(self, function: AsyncInspect[L]) -> Left[L]:
await function(self.value)
return self
async def inspect_right_await(self, function: AsyncInspect[R]) -> Left[L]:
return self
def flip(self) -> Right[L]:
return Right(self.value)
def map_left(self, function: Unary[L, M]) -> Left[M]:
return self.create(function(self.value))
async def map_left_await(self, function: AsyncUnary[L, M]) -> Left[M]:
return self.create(await function(self.value))
def map_right(self, function: Unary[R, S]) -> Left[L]:
return self
async def map_right_await(self, function: AsyncUnary[R, S]) -> Left[L]:
return self
def map(self: Left[T], function: Unary[T, U]) -> Left[U]:
return self.create(function(self.value))
async def map_await(self: Left[T], function: AsyncUnary[T, U]) -> Left[U]:
return self.create(await function(self.value))
def map_either(self, left: Unary[L, M], right: Unary[R, S]) -> Left[M]:
return self.create(left(self.value))
async def map_either_await(self, left: AsyncUnary[L, M], right: Unary[R, S]) -> Left[M]:
return self.create(await left(self.value))
def either(self, left: Unary[L, T], right: Unary[R, T]) -> T:
return left(self.value)
async def either_await(self, left: AsyncUnary[L, T], right: AsyncUnary[R, T]) -> T:
return await left(self.value)
def left_and_then(self, function: Unary[L, Either[M, R]]) -> Either[M, R]:
return function(self.value)
async def left_and_then_await(self, function: AsyncUnary[L, Either[M, R]]) -> Either[M, R]:
return await function(self.value)
def right_and_then(self, function: Unary[R, Either[L, S]]) -> Left[L]:
return self
async def right_and_then_await(self, function: AsyncUnary[R, Either[L, S]]) -> Left[L]:
return self
def iter_left(self) -> Iterator[L]:
return once(self.value)
def iter_right(self) -> Iterator[Never]:
return empty()
def iter_either(self: Left[T]) -> Iterator[T]:
return once(self.value)
def async_iter_left(self) -> AsyncIterator[L]:
return async_once(self.value)
def async_iter_right(self) -> AsyncIterator[Never]:
return async_empty()
def async_iter_either(self: Left[T]) -> AsyncIterator[T]:
return async_once(self.value)
def contains_left(self, value: M) -> bool:
return self.value == value
def contains_right(self, value: S) -> Literal[False]:
return False
def contains(self: Left[T], value: U) -> bool:
return self.value == value
def into_result(self) -> Ok[L]:
return Ok(self.value)
|