Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c053100

Browse files
Update README.md (#8)
1 parent 8db151c commit c053100

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

‎README.md‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ __Table of Contents__
2323
* [Function Composition](#function-composition)
2424
* [Continuation (TODO)](#continuation-todo)
2525
* [Point-Free Style (TODO)](#point-free-style-todo)
26-
* [Predicate (TODO)](#predicate-todo)
26+
* [Predicate](#predicate)
2727
* [Contracts (TODO)](#contracts-todo)
2828
* [Category (TODO)](#category-todo)
2929
* [Value (TODO)](#value-todo)
@@ -439,14 +439,27 @@ Writing functions where the definition does not explicitly identify the argument
439439

440440
Points-free function definitions look just like normal assignments without `def` or `lambda`.
441441

442-
## Predicate (TODO)
443442

444-
A predicate is a function that returns true or false for a given value. A common use of a predicate is as the callback for array filter.
443+
## Predicate
444+
445+
A predicate is a function that returns true or false for a given value.
446+
So, basically a predicate is an alias for `Callable[[_ValueType], bool]`.
447+
448+
It is very useful when working with `if`, `all`, `any`, etc.
445449

446450
```python
447-
# TODO
451+
>>> def is_long(item: str) -> bool:
452+
... return len(item) > 3
453+
454+
>>> assert all(is_long(item) for item in ['1234', 'abcd'])
455+
>>>
448456
```
449457

458+
__Futher reading__
459+
* [Predicate logic](https://en.wikipedia.org/wiki/Predicate_functor_logic)
460+
* [`cond` docs](https://returns.readthedocs.io/en/latest/pages/pointfree.html#cond)
461+
462+
450463
## Contracts (TODO)
451464

452465
A contract specifies the obligations and guarantees of the behavior from a function or expression at runtime. This acts as a set of rules that are expected from the input and output of a function or expression, and errors are generally reported whenever a contract is violated.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /