2626import builtins
2727import functools
2828import 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
3030
3131from expression .core import Case , Option , SupportsLessThan , identity , pipe
3232
@@ -350,18 +350,7 @@ def __iter__(self) -> Iterator[TSource]:
350350 return builtins .iter (xs )
351351
352352
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 ]]:
365354 """Wraps the given enumerations as a single concatenated
366355 enumeration."""
367356
@@ -371,7 +360,7 @@ def _(source: Iterable[TSource]) -> Iterable[TSource]:
371360 return _
372361
373362
374- def choose (chooser : Callable [[TSource ], Option [TResult ]]) -> Projection [ TSource , TResult ]:
363+ def choose (chooser : Callable [[TSource ], Option [TResult ]]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
375364 """Choose items from the sequence.
376365
377366 Applies the given function to each element of the list. Returns
@@ -395,7 +384,7 @@ def mapper(x: TSource) -> Iterable[TResult]:
395384 return _choose
396385
397386
398- def collect (mapping : Callable [[TSource ], Iterable [TResult ]]) -> Projection [ TSource , TResult ]:
387+ def collect (mapping : Callable [[TSource ], Iterable [TResult ]]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
399388 def _collect (source : Iterable [TSource ]) -> Iterable [TResult ]:
400389 def gen ():
401390 for xs in source :
@@ -444,7 +433,7 @@ def delay(generator: Callable[[], Iterable[TSource]]) -> Iterable[TSource]:
444433"""The empty sequence."""
445434
446435
447- def filter (predicate : Callable [[TSource ], bool ]) -> Projection [ TSource , TSource ]:
436+ def filter (predicate : Callable [[TSource ], bool ]) -> Callable [[ Iterable [ TSource ]], Iterable [ TSource ] ]:
448437 """Filter sequence.
449438
450439 Filters the sequence to a new sequence containing only the
@@ -609,7 +598,7 @@ def length(source: Seq[Any]) -> int:
609598 return builtins .sum (1 for _ in source )
610599
611600
612- def map (mapper : Callable [[TSource ], TResult ]) -> Projection [ TSource , TResult ]:
601+ def map (mapper : Callable [[TSource ], TResult ]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
613602 """Map source sequence.
614603
615604 Builds a new collection whose elements are the results of
@@ -641,7 +630,7 @@ def gen():
641630 return _map
642631
643632
644- def mapi (mapping : Callable [[int , TSource ], TResult ]) -> Projection [ TSource , TResult ]:
633+ def mapi (mapping : Callable [[int , TSource ], TResult ]) -> Callable [[ Iterable [ TSource ]], Iterable [ TResult ] ]:
645634 """Map list with index.
646635
647636 Builds a new collection whose elements are the results of
@@ -766,7 +755,7 @@ def singleton(item: TSource) -> Seq[TSource]:
766755 return Seq ([item ])
767756
768757
769- def skip (count : int ) -> Projection [ Any , Any ]:
758+ def skip (count : int ) -> Callable [[ Iterable [ TSource ]], Iterable [ TSource ] ]:
770759 """Returns a sequence that skips N elements of the underlying
771760 sequence and then yields the remaining elements of the sequence.
772761
@@ -809,7 +798,7 @@ def tail(source: Iterable[TSource]) -> Iterable[TSource]:
809798 return proj (source )
810799
811800
812- def take (count : int ) -> Projection [ Any , Any ]:
801+ def take (count : int ) -> Callable [[ Iterable [ TSource ]], Iterable [ TSource ] ]:
813802 """Returns the first N elements of the sequence.
814803
815804 Args:
@@ -932,7 +921,6 @@ def _zip(source2: Iterable[TResult]) -> Iterable[Tuple[TSource, TResult]]:
932921 "sum_by" ,
933922 "tail" ,
934923 "take" ,
935- "Projection" ,
936924 "unfold" ,
937925 "zip" ,
938926]
0 commit comments