Can you pattern match collection types?
- Langage dominant
- Python
- Étoiles
- 21
- Forks
- 1
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
In Erlang it often ends up being useful to model the state invariants as pattern matches of expectations of complex types.
For instance, an IRC chat room that is empty the first user to join it becomes the operator, if it is ever empty again the new first user to join it becomes the operator.
You could explicitly track the empty state, but it is much easier to have the function that decides if it should op the joining user to simply dispatch on a match of the user list.
In bagel I'd expect this to look something like…
``` python
class Chatroom:
users = List
operator = Option(User)
...
def user_joining(self, user: User):
match self.users:
as []:
self.operator = Some(user)
as users:
pass
self.users.append(user)
```
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.