Skip to content

Commit

Permalink
Expose the Record type on the root funml package
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinitto committed Feb 15, 2023
1 parent 44ea434 commit f020c13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ FunML
===

::: funml
options:
filters:
- "!Record"

Types
===
Expand Down
3 changes: 2 additions & 1 deletion funml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
is_ok,
is_some,
)
from .data.records import record, to_dict
from .data.records import record, to_dict, Record
from .data.lists import l, imap, ifilter, ireduce
from .pipeline import execute

Expand All @@ -47,6 +47,7 @@
"is_some",
"is_none",
"record",
"Record",
"to_dict",
"l",
"imap",
Expand Down
19 changes: 17 additions & 2 deletions funml/data/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Color:
r: int
g: int
b: int
a: int
a: int = 1
blue = Color(r=0, g=0, b=255, a=1)
red = Color(r=255, g=0, b=0, a=1)
green = Color(r=0, g=255, b=0, a=1)
green = Color(r=0, g=255, b=0)
print(blue)
# prints: {'r': 0, 'g': 0, 'b': 255, 'a': 1}
Expand Down Expand Up @@ -120,6 +120,21 @@ class Record(types.MLType):
the expected attributes and then is used to create new instances
of that record type.
This type is usually not used directly but rather we use the [@record](funml.record) decorator
Example:
```python
import funml as ml
@ml.record
class Color:
r: int
g: int
b: int
a: int = 1
```
Args:
kwargs: the data for the current record instance.
Expand Down

0 comments on commit f020c13

Please sign in to comment.