|
35 | 35 | neg as primitive_neg, pos as primitive_pos, |
36 | 36 | and_ as primitive_and, xor as primitive_xor, or_ as primitive_or, |
37 | 37 | lshift as primitive_lshift, rshift as primitive_rshift, |
38 | | - invert as primitive_invert) |
| 38 | + invert as primitive_invert, |
| 39 | + lt as primitive_lt, le as primitive_le, |
| 40 | + eq as primitive_eq, ne as primitive_ne, |
| 41 | + ge as primitive_ge, gt as primitive_gt) |
39 | 42 |
|
40 | 43 | from .it import take, rev, window |
41 | 44 | from .gmemo import imemoize, gmemoize |
@@ -563,7 +566,28 @@ def __or__(self, other): |
563 | 566 | return sor(self, other) |
564 | 567 | def __ror__(self, other): |
565 | 568 | return sor(other, self) |
566 | | - # TODO: conversion (bool, complex, int, float) and comparison operators? Do we want those? |
| 569 | + # Can't do this because each of these conversion operators must return an |
| 570 | + # instance of that primitive type. |
| 571 | + # def __bool__(self): |
| 572 | + # return sbool(self) |
| 573 | + # def __complex__(self): |
| 574 | + # return scomplex(self) |
| 575 | + # def __int__(self): |
| 576 | + # return sint(self) |
| 577 | + # def __float__(self): |
| 578 | + # return sfloat(self) |
| 579 | + def __lt__(self, other): |
| 580 | + return slt(self, other) |
| 581 | + def __le__(self, other): |
| 582 | + return sle(self, other) |
| 583 | + def __eq__(self, other): |
| 584 | + return seq(self, other) |
| 585 | + def __ne__(self, other): |
| 586 | + return sne(self, other) |
| 587 | + def __ge__(self, other): |
| 588 | + return sge(self, other) |
| 589 | + def __gt__(self, other): |
| 590 | + return sgt(self, other) |
567 | 591 |
|
568 | 592 | def mg(gfunc): |
569 | 593 | """Decorator: make gfunc m() the returned generator instances. |
@@ -688,6 +712,30 @@ def sround(a, *ndigits): |
688 | 712 | https://docs.python.org/3/library/operator.html#operator.not_ |
689 | 713 | """ |
690 | 714 |
|
| 715 | +# Can't do this because each of these conversion operators must return an |
| 716 | +# instance of that primitive type. |
| 717 | +# |
| 718 | +# sbool = _make_termwise_stream_unop(bool) |
| 719 | +# sbool.__doc__ = """Termwise bool(a) for an iterable.""" |
| 720 | +# scomplex = _make_termwise_stream_unop(complex) |
| 721 | +# scomplex.__doc__ = """Termwise complex(a) for an iterable.""" |
| 722 | +# sint = _make_termwise_stream_unop(int) |
| 723 | +# sint.__doc__ = """Termwise int(a) for an iterable.""" |
| 724 | +# sfloat = _make_termwise_stream_unop(float) |
| 725 | +# sfloat.__doc__ = """Termwise float(a) for an iterable.""" |
| 726 | + |
| 727 | +slt = _make_termwise_stream_binop(primitive_lt) |
| 728 | +slt.__doc__ = """Termwise a < b when one or both are iterables.""" |
| 729 | +sle = _make_termwise_stream_binop(primitive_le) |
| 730 | +sle.__doc__ = """Termwise a <= b when one or both are iterables.""" |
| 731 | +seq = _make_termwise_stream_binop(primitive_eq) |
| 732 | +seq.__doc__ = """Termwise a == b when one or both are iterables.""" |
| 733 | +sne = _make_termwise_stream_binop(primitive_ne) |
| 734 | +sne.__doc__ = """Termwise a != b when one or both are iterables.""" |
| 735 | +sge = _make_termwise_stream_binop(primitive_ge) |
| 736 | +sge.__doc__ = """Termwise a >= b when one or both are iterables.""" |
| 737 | +sgt = _make_termwise_stream_binop(primitive_gt) |
| 738 | +sgt.__doc__ = """Termwise a > b when one or both are iterables.""" |
691 | 739 |
|
692 | 740 | # ----------------------------------------------------------------------------- |
693 | 741 |
|
|
0 commit comments