Skip to Content
Hands-On Reactive Programming with Python
book

Hands-On Reactive Programming with Python

by Romain Picard
October 2018
Intermediate to advanced
420 pages
10h 26m
English
Packt Publishing
Content preview from Hands-On Reactive Programming with Python

Using dataclasses

Before Python 3.7, namedtuple was the easiest way to use class-like objects without having to implement a class for each object with the associated constructor. Since Python 3.7, dataclasses can also be used for this purpose. dataclass allows a class to easily declare that it contains only data. This is available in the dataclasses module of the standard library. The same snippet can be written as follows with dataclasses:

from dataclasses import dataclass@dataclass
class Basket:
    count
    what@dataclass
class FruitCount:
    count
    doubleobs = Observable.from_([Basket(count=5, what='apple'),                        Basket(count=3, what='orange')]) \    .filter(lambda i: i.what == 'apple') \     .map(lambda i: i.count) \ .map(lamda i: FruitCount(count=i, double=i*2)) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Programming with Design Patterns

Python Programming with Design Patterns

James W. Cooper

Publisher Resources

ISBN: 9781789138726Supplemental Content