26
26
import builtins
27
27
import functools
28
28
import itertools
29
- from typing import TYPE_CHECKING , Any , Callable , Iterable , Iterator , Optional , Protocol , Tuple , TypeVar , cast , overload
29
+ from typing import TYPE_CHECKING , Any , Callable , Iterable , Iterator , Optional , Tuple , TypeVar , cast , overload
30
30
31
31
from expression .core import Case , Option , SupportsLessThan , identity , pipe
32
32
@@ -350,18 +350,7 @@ def __iter__(self) -> Iterator[TSource]:
350
350
return builtins .iter (xs )
351
351
352
352
353
- class Projection (Protocol [TSourceIn , TResultOut ]):
354
- """Sequence transformation protocol.
355
-
356
- A sequence transformation protocol that encapsulates a function of
357
- type `Iterable[TSource]) -> Iterable[TResult]`
358
- """
359
-
360
- def __call__ (self , __source : Iterable [TSourceIn ]) -> Iterable [TResultOut ]:
361
- raise NotImplementedError
362
-
363
-
364
- def append (* others : Iterable [TSource ]) -> Projection [TSource , TSource ]:
353
+ def append (* others : Iterable [TSource ]) -> Callable [[Iterable [TSource ]], Iterable [TSource ]]:
365
354
"""Wraps the given enumerations as a single concatenated
366
355
enumeration."""
367
356
@@ -371,7 +360,7 @@ def _(source: Iterable[TSource]) -> Iterable[TSource]:
371
360
return _
372
361
373
362
374
- def choose (chooser : Callable [[TSource ], Option [TResult ]]) -> Projection [ TSource , TResult ]:
363
+ def choose (chooser : Callable [[TSource ], Option [TResult ]]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
375
364
"""Choose items from the sequence.
376
365
377
366
Applies the given function to each element of the list. Returns
@@ -395,7 +384,7 @@ def mapper(x: TSource) -> Iterable[TResult]:
395
384
return _choose
396
385
397
386
398
- def collect (mapping : Callable [[TSource ], Iterable [TResult ]]) -> Projection [ TSource , TResult ]:
387
+ def collect (mapping : Callable [[TSource ], Iterable [TResult ]]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
399
388
def _collect (source : Iterable [TSource ]) -> Iterable [TResult ]:
400
389
def gen ():
401
390
for xs in source :
@@ -444,7 +433,7 @@ def delay(generator: Callable[[], Iterable[TSource]]) -> Iterable[TSource]:
444
433
"""The empty sequence."""
445
434
446
435
447
- def filter (predicate : Callable [[TSource ], bool ]) -> Projection [ TSource , TSource ]:
436
+ def filter (predicate : Callable [[TSource ], bool ]) -> Callable [[ Iterable [ TSource ]], Iterable [ TSource ] ]:
448
437
"""Filter sequence.
449
438
450
439
Filters the sequence to a new sequence containing only the
@@ -609,7 +598,7 @@ def length(source: Seq[Any]) -> int:
609
598
return builtins .sum (1 for _ in source )
610
599
611
600
612
- def map (mapper : Callable [[TSource ], TResult ]) -> Projection [ TSource , TResult ]:
601
+ def map (mapper : Callable [[TSource ], TResult ]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
613
602
"""Map source sequence.
614
603
615
604
Builds a new collection whose elements are the results of
@@ -641,7 +630,7 @@ def gen():
641
630
return _map
642
631
643
632
644
- def mapi (mapping : Callable [[int , TSource ], TResult ]) -> Projection [ TSource , TResult ]:
633
+ def mapi (mapping : Callable [[int , TSource ], TResult ]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
645
634
"""Map list with index.
646
635
647
636
Builds a new collection whose elements are the results of
@@ -766,7 +755,7 @@ def singleton(item: TSource) -> Seq[TSource]:
766
755
return Seq ([item ])
767
756
768
757
769
- def skip (count : int ) -> Projection [ Any , Any ]:
758
+ def skip (count : int ) -> Callable [[ Iterable [ TSource ]], Iterable [ TSource ] ]:
770
759
"""Returns a sequence that skips N elements of the underlying
771
760
sequence and then yields the remaining elements of the sequence.
772
761
@@ -809,7 +798,7 @@ def tail(source: Iterable[TSource]) -> Iterable[TSource]:
809
798
return proj (source )
810
799
811
800
812
- def take (count : int ) -> Projection [ Any , Any ]:
801
+ def take (count : int ) -> Callable [[ Iterable [ TSource ]], Iterable [ TSource ] ]:
813
802
"""Returns the first N elements of the sequence.
814
803
815
804
Args:
@@ -932,7 +921,6 @@ def _zip(source2: Iterable[TResult]) -> Iterable[Tuple[TSource, TResult]]:
932
921
"sum_by" ,
933
922
"tail" ,
934
923
"take" ,
935
- "Projection" ,
936
924
"unfold" ,
937
925
"zip" ,
938
926
]
0 commit comments