@@ -3,3 +3,99 @@ Library for sculpting objects from others
33
44### Installing
55``` pip install sculpting ```
6+
7+ ### Examples
8+ Create an object based on another
9+ ``` python
10+ from dataclasses import dataclass
11+
12+ from pyhandling import by, then
13+ from sculpting import Sculpture
14+
15+
16+ @dataclass
17+ class User :
18+ id : int
19+ username: str
20+ password: str
21+
22+
23+ original = User(0 , " William" , " 1234" )
24+
25+ sculture = Sculpture(
26+ original,
27+ name = " username" ,
28+ password_hash = (getattr | by| " password" ) | then>> hash
29+ )
30+ ```
31+
32+ which is mapped with the original
33+ ``` python
34+ sculture.name
35+ sculture.password_hash
36+ ```
37+ ```
38+ William
39+ 1670106271132722890
40+ ```
41+
42+ even with its modification
43+ ``` python
44+ sculture.name = " Not William"
45+ original.username
46+ ```
47+ ```
48+ Not William
49+ ```
50+
51+ which can be custom
52+ ``` python
53+ from sculpting import AttributeMap, changing_attribute_map_for
54+ from sculpting.tools import setting_of_attr
55+
56+
57+ transforming_sculpture = Sculpture(
58+ original,
59+ id_of_others = AttributeMap(
60+ getattr | by| " id_of_others" ,
61+ setting_of_attr(" id_of_others" , value_transformer = tuple )
62+ ),
63+ synonym_for_id_of_others = changing_attribute_map_for(" id_of_others" , tuple ) # Shortcut for recording above
64+ )
65+
66+ transforming_sculpture.synonym_for_id_of_others = range (1 , 5 )
67+ original.id_of_others
68+ ```
69+ ```
70+ (1, 2, 3, 4)
71+ ```
72+
73+ using standard tools
74+ ``` python
75+ from datetime import datetime
76+ from time import sleep
77+
78+ from pyhandling import close, operation_by, eventually, returnly
79+ from sculpting import read_only_attribute_map_as
80+ from sculpting.tools import once
81+
82+
83+ standard_tool_sculpture_from = (
84+ close(Sculpture)(
85+ id = read_only_attribute_map_as((getattr | by| ' id' ) | then>> operation_by(' *' , 2 )),
86+ creation_time = once(eventually(datetime.now))
87+ )
88+ | then>> returnly(getattr | by| " creation_time" )
89+ )
90+
91+ standard_tool_sculpture = standard_tool_sculpture_from(original)
92+ print (datetime.now().time(), " - at initialization" )
93+
94+ sleep(3 )
95+
96+ print (standard_tool_sculpture.creation_time.time(), " - at getting" )
97+ ```
98+ ```
99+ 16:10:16.045444 - at initialization
100+ 16:10:16.045444 - at getting
101+ ```
0 commit comments