Skip to content

Commit

Permalink
Add curried version of the multiple argument predicate functions (#216)
Browse files Browse the repository at this point in the history
* Add curried version of the multiple argument predicate functions

* Use `_cmp` suffix

---------

Co-authored-by: DeviousStoat <devious@stoat.com>
  • Loading branch information
DeviousStoat and DeviousStoat committed Feb 5, 2024
1 parent 940a843 commit 0dfc47d
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/pydash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@
)
from .predicates import (
eq,
eq_cmp,
gt,
gt_cmp,
gte,
gte_cmp,
in_range,
in_range_cmp,
is_associative,
is_blank,
is_boolean,
Expand All @@ -227,21 +231,27 @@
is_dict,
is_empty,
is_equal,
is_equal_cmp,
is_equal_with,
is_equal_with_cmp,
is_error,
is_even,
is_float,
is_function,
is_increasing,
is_indexed,
is_instance_of,
is_instance_of_cmp,
is_integer,
is_iterable,
is_json,
is_list,
is_match,
is_match_cmp,
is_match_with,
is_match_with_cmp,
is_monotone,
is_monotone_cmp,
is_nan,
is_negative,
is_none,
Expand All @@ -257,7 +267,9 @@
is_tuple,
is_zero,
lt,
lt_cmp,
lte,
lte_cmp,
)
from .strings import (
camel_case,
Expand Down Expand Up @@ -577,9 +589,13 @@
"update_with",
"values",
"eq",
"eq_cmp",
"gt",
"gt_cmp",
"gte",
"gte_cmp",
"in_range",
"in_range_cmp",
"is_associative",
"is_blank",
"is_boolean",
Expand All @@ -589,21 +605,27 @@
"is_dict",
"is_empty",
"is_equal",
"is_equal_cmp",
"is_equal_with",
"is_equal_with_cmp",
"is_error",
"is_even",
"is_float",
"is_function",
"is_increasing",
"is_indexed",
"is_instance_of",
"is_instance_of_cmp",
"is_integer",
"is_iterable",
"is_json",
"is_list",
"is_match",
"is_match_cmp",
"is_match_with",
"is_match_with_cmp",
"is_monotone",
"is_monotone_cmp",
"is_nan",
"is_negative",
"is_none",
Expand All @@ -619,7 +641,9 @@
"is_tuple",
"is_zero",
"lt",
"lt_cmp",
"lte",
"lte_cmp",
"camel_case",
"capitalize",
"chars",
Expand Down
44 changes: 44 additions & 0 deletions src/pydash/chaining/all_funcs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2782,21 +2782,39 @@ class AllFuncs:
def eq(self: "Chain[t.Any]", other: t.Any) -> "Chain[bool]":
return self._wrap(pyd.eq)(other)

def eq_cmp(self: "Chain[T]") -> "Chain[t.Callable[[T], bool]]":
return self._wrap(pyd.eq_cmp)()

def gt(self: "Chain['SupportsDunderGT[T]']", other: T) -> "Chain[bool]":
return self._wrap(pyd.gt)(other)

def gt_cmp(self: "Chain[T]") -> "Chain[t.Callable[['SupportsDunderGT[T]'], bool]]":
return self._wrap(pyd.gt_cmp)()

def gte(self: "Chain['SupportsDunderGE[T]']", other: T) -> "Chain[bool]":
return self._wrap(pyd.gte)(other)

def gte_cmp(self: "Chain[T]") -> "Chain[t.Callable[['SupportsDunderGE[T]'], bool]]":
return self._wrap(pyd.gte_cmp)()

def lt(self: "Chain['SupportsDunderLT[T]']", other: T) -> "Chain[bool]":
return self._wrap(pyd.lt)(other)

def lt_cmp(self: "Chain[T]") -> "Chain[t.Callable[['SupportsDunderLT[T]'], bool]]":
return self._wrap(pyd.lt_cmp)()

def lte(self: "Chain['SupportsDunderLE[T]']", other: T) -> "Chain[bool]":
return self._wrap(pyd.lte)(other)

def lte_cmp(self: "Chain[T]") -> "Chain[t.Callable[['SupportsDunderLE[T]'], bool]]":
return self._wrap(pyd.lte_cmp)()

def in_range(self: "Chain[t.Any]", start: t.Any = 0, end: t.Any = None) -> "Chain[bool]":
return self._wrap(pyd.in_range)(start, end)

def in_range_cmp(self: "Chain[t.Any]", end: t.Any = None) -> "Chain[t.Callable[[t.Any], bool]]":
return self._wrap(pyd.in_range_cmp)(end)

def is_associative(self: "Chain[t.Any]") -> "Chain[bool]":
return self._wrap(pyd.is_associative)()

Expand Down Expand Up @@ -2826,6 +2844,9 @@ class AllFuncs:
def is_equal(self: "Chain[t.Any]", other: t.Any) -> "Chain[bool]":
return self._wrap(pyd.is_equal)(other)

def is_equal_cmp(self: "Chain[T]") -> "Chain[t.Callable[[T], bool]]":
return self._wrap(pyd.is_equal_cmp)()

@t.overload
def is_equal_with(
self: "Chain[T]", other: T2, customizer: t.Callable[[T, T2], T3]
Expand All @@ -2839,6 +2860,11 @@ class AllFuncs:
def is_equal_with(self, other, customizer):
return self._wrap(pyd.is_equal_with)(other, customizer)

def is_equal_with_cmp(
self: "Chain[T]", customizer: t.Callable[[T, T], T3]
) -> "Chain[t.Callable[[T], T3]]":
return self._wrap(pyd.is_equal_with_cmp)(customizer)

def is_error(self: "Chain[t.Any]") -> "Chain[bool]":
return self._wrap(pyd.is_error)()

Expand All @@ -2864,6 +2890,11 @@ class AllFuncs:
) -> "Chain[bool]":
return self._wrap(pyd.is_instance_of)(types)

def is_instance_of_cmp(
self: "Chain[t.Union[type, t.Tuple[type, ...]]]",
) -> "Chain[t.Callable[[t.Any], bool]]":
return self._wrap(pyd.is_instance_of_cmp)()

def is_integer(self: "Chain[t.Any]") -> "Chain[bool]":
return self._wrap(pyd.is_integer)()

Expand All @@ -2879,6 +2910,9 @@ class AllFuncs:
def is_match(self: "Chain[t.Any]", source: t.Any) -> "Chain[bool]":
return self._wrap(pyd.is_match)(source)

def is_match_cmp(self: "Chain[t.Any]") -> "Chain[t.Callable[[t.Any], bool]]":
return self._wrap(pyd.is_match_cmp)()

def is_match_with(
self: "Chain[t.Any]",
source: t.Any,
Expand All @@ -2889,11 +2923,21 @@ class AllFuncs:
) -> "Chain[bool]":
return self._wrap(pyd.is_match_with)(source, customizer, _key, _obj, _source)

def is_match_with_cmp(
self: "Chain[t.Any]", customizer: t.Any = None
) -> "Chain[t.Callable[[t.Any], bool]]":
return self._wrap(pyd.is_match_with_cmp)(customizer)

def is_monotone(
self: "Chain[t.Union[T, t.List[T]]]", op: t.Callable[[T, T], t.Any]
) -> "Chain[bool]":
return self._wrap(pyd.is_monotone)(op)

def is_monotone_cmp(
self: "Chain[t.Callable[[T, T], t.Any]]",
) -> "Chain[t.Callable[[t.Union[T, t.List[T]]], bool]]":
return self._wrap(pyd.is_monotone_cmp)()

def is_nan(self: "Chain[t.Any]") -> "Chain[bool]":
return self._wrap(pyd.is_nan)()

Expand Down
Loading

0 comments on commit 0dfc47d

Please sign in to comment.