-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
complete todos #52
base: master
Are you sure you want to change the base?
complete todos #52
Conversation
complete todos
Update README.md
rm build test badge since I don't think it does anything atm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WOW! This is just great! Thank you some much for working on this.
I have a few comments, though :)
@@ -1,7 +1,5 @@ | |||
# Functional Programming Jargon | |||
|
|||
[![Build Status](https://github.com/dry-python/functional-jargon-python/workflows/test/badge.svg?event=push)](https://github.com/dry-python/functional-jargon-python/actions?query=workflow%3Atest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this badge?
|
||
```python | ||
# TODO | ||
def make_adder(x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer to annotate all functions in this article.
|
||
```python | ||
# TODO | ||
def make_adder(x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def make_adder(x): | |
from typing import Callable | |
def make_adder(x: int) -> Callable[[int], int]: |
|
||
```python | ||
# TODO | ||
def make_adder(x): | ||
def adder(y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def adder(y): | |
def adder(y: int) -> int: |
|
||
```python | ||
# TODO | ||
def print_numbers(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def print_numbers(): | |
from typing import Iterator | |
def print_numbers() -> Iterator[None]: |
|
||
```python | ||
# TODO | ||
``` | ||
from typing import Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from typing import Union |
if isinstance(value, int): | ||
return f"Integer: {value}" | ||
elif isinstance(value, str): | ||
return f"String: {value}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good place to use typing.assert_never
from typing import NamedTuple | ||
|
||
# A product type representing a point in 2D space | ||
class Point(NamedTuple): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can add a comment that tuple[]
is just fine as well.
|
||
NoneValue = NoneType() | ||
|
||
Option = Union[Some[T], NoneType] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option = Union[Some[T], NoneType] | |
Option = Some[T] | NoneType |
Option is useful for composing functions that might not return a value. | ||
This pattern forces the programmer to explicitly handle the case where a value might be missing, leading to safer and more predictable code. | ||
|
||
In languages like Haskell, this type is known as `Maybe`, with the variants being `Just` (for `Some`) and `Nothing` (for `None`). In Rust, it's called `Option`, with the variants `Some` and `None`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use dry-python
's language for Maybe
here :)
complete todos