@@ -13,19 +13,17 @@ package object quicklens extends LowPriorityImplicits {
13
13
private [softwaremill] def canOnlyBeUsedInsideModify (method : String ) =
14
14
s " $method can only be used inside modify "
15
15
16
- /**
17
- * Create an object allowing modifying the given (deeply nested) field accessible in a `case class` hierarchy
18
- * via `path` on the given `obj`.
16
+ /** Create an object allowing modifying the given (deeply nested) field accessible in a `case class` hierarchy via
17
+ * `path` on the given `obj`.
19
18
*
20
19
* All modifications are side-effect free and create copies of the original objects.
21
20
*
22
21
* You can use `.each` to traverse options, lists, etc.
23
22
*/
24
23
def modify [T , U ](obj : T )(path : T => U ): PathModify [T , U ] = macro QuicklensMacros .modify_impl[T , U ]
25
24
26
- /**
27
- * Create an object allowing modifying the given (deeply nested) fields accessible in a `case class` hierarchy
28
- * via `paths` on the given `obj`.
25
+ /** Create an object allowing modifying the given (deeply nested) fields accessible in a `case class` hierarchy via
26
+ * `paths` on the given `obj`.
29
27
*
30
28
* All modifications are side-effect free and create copies of the original objects.
31
29
*
@@ -36,19 +34,17 @@ package object quicklens extends LowPriorityImplicits {
36
34
37
35
implicit class ModifyPimp [T ](t : T ) {
38
36
39
- /**
40
- * Create an object allowing modifying the given (deeply nested) field accessible in a `case class` hierarchy
41
- * via `path` on the given `obj`.
37
+ /** Create an object allowing modifying the given (deeply nested) field accessible in a `case class` hierarchy via
38
+ * `path` on the given `obj`.
42
39
*
43
40
* All modifications are side-effect free and create copies of the original objects.
44
41
*
45
42
* You can use `.each` to traverse options, lists, etc.
46
43
*/
47
44
def modify [U ](path : T => U ): PathModify [T , U ] = macro QuicklensMacros .modifyPimp_impl[T , U ]
48
45
49
- /**
50
- * Create an object allowing modifying the given (deeply nested) fields accessible in a `case class` hierarchy
51
- * via `paths` on the given `obj`.
46
+ /** Create an object allowing modifying the given (deeply nested) fields accessible in a `case class` hierarchy via
47
+ * `paths` on the given `obj`.
52
48
*
53
49
* All modifications are side-effect free and create copies of the original objects.
54
50
*
@@ -59,16 +55,16 @@ package object quicklens extends LowPriorityImplicits {
59
55
60
56
case class PathModify [T , U ](obj : T , doModify : (T , U => U ) => T ) {
61
57
62
- /**
63
- * Transform the value of the field(s) using the given function.
58
+ /** Transform the value of the field(s) using the given function.
64
59
*
65
- * @return A copy of the root object with the (deeply nested) field(s) modified.
60
+ * @return
61
+ * A copy of the root object with the (deeply nested) field(s) modified.
66
62
*/
67
63
def using (mod : U => U ): T = doModify(obj, mod)
68
64
69
- /** An alias for [[using ]]. Explicit calls to [[using ]] are preferred over this alias, but quicklens provides
70
- * this option because code auto-formatters (like scalafmt) will generally not keep [[modify ]]/[[using ]]
71
- * pairs on the same line, leading to code like
65
+ /** An alias for [[using ]]. Explicit calls to [[using ]] are preferred over this alias, but quicklens provides this
66
+ * option because code auto-formatters (like scalafmt) will generally not keep [[modify ]]/[[using ]] pairs on the
67
+ * same line, leading to code like
72
68
* {{{
73
69
* x
74
70
* .modify(_.foo)
@@ -82,38 +78,37 @@ package object quicklens extends LowPriorityImplicits {
82
78
* .modify(_.foo)(newFoo :: _)
83
79
* .modify(_.bar)(_ + newBar)
84
80
* }}}
85
- * * /
81
+ */
86
82
final def apply (mod : U => U ): T = using(mod)
87
83
88
- /**
89
- * Transform the value of the field(s) using the given function, if the condition is true. Otherwise, returns the
84
+ /** Transform the value of the field(s) using the given function, if the condition is true. Otherwise, returns the
90
85
* original object unchanged.
91
86
*
92
- * @return A copy of the root object with the (deeply nested) field(s) modified, if `condition` is true.
87
+ * @return
88
+ * A copy of the root object with the (deeply nested) field(s) modified, if `condition` is true.
93
89
*/
94
90
def usingIf (condition : Boolean )(mod : U => U ): T = if (condition) doModify(obj, mod) else obj
95
91
96
- /**
97
- * Set the value of the field(s) to a new value.
92
+ /** Set the value of the field(s) to a new value.
98
93
*
99
- * @return A copy of the root object with the (deeply nested) field(s) set to the new value.
94
+ * @return
95
+ * A copy of the root object with the (deeply nested) field(s) set to the new value.
100
96
*/
101
97
def setTo (v : U ): T = doModify(obj, _ => v)
102
98
103
- /**
104
- * Set the value of the field(s) to a new value, if it is defined. Otherwise, returns the original object
99
+ /** Set the value of the field(s) to a new value, if it is defined. Otherwise, returns the original object
105
100
* unchanged.
106
101
*
107
- * @return A copy of the root object with the (deeply nested) field(s) set to the new value, if it is defined.
102
+ * @return
103
+ * A copy of the root object with the (deeply nested) field(s) set to the new value, if it is defined.
108
104
*/
109
105
def setToIfDefined (v : Option [U ]): T = v.fold(obj)(setTo)
110
106
111
- /**
112
- * Set the value of the field(s) to a new value, if the condition is true. Otherwise, returns the original object
107
+ /** Set the value of the field(s) to a new value, if the condition is true. Otherwise, returns the original object
113
108
* unchanged.
114
109
*
115
- * @return A copy of the root object with the (deeply nested) field(s) set to the new value, if `condition` is
116
- * true.
110
+ * @return
111
+ * A copy of the root object with the (deeply nested) field(s) set to the new value, if `condition` is true.
117
112
*/
118
113
def setToIf (condition : Boolean )(v : => U ): T = if (condition) setTo(v) else obj
119
114
}
@@ -142,38 +137,32 @@ package object quicklens extends LowPriorityImplicits {
142
137
143
138
self =>
144
139
145
- /**
146
- * see [[PathModify.using ]]
140
+ /** see [[PathModify.using ]]
147
141
*/
148
142
def using (mod : U => U ): T => T = obj => doModify(obj, mod)
149
143
150
- /**
151
- * see [[PathModify.usingIf ]]
144
+ /** see [[PathModify.usingIf ]]
152
145
*/
153
146
def usingIf (condition : Boolean )(mod : U => U ): T => T =
154
147
obj =>
155
148
if (condition) doModify(obj, mod)
156
149
else obj
157
150
158
- /**
159
- * see [[PathModify.setTo ]]
151
+ /** see [[PathModify.setTo ]]
160
152
*/
161
153
def setTo (v : U ): T => T = obj => doModify(obj, _ => v)
162
154
163
- /**
164
- * see [[PathModify.setToIfDefined ]]
155
+ /** see [[PathModify.setToIfDefined ]]
165
156
*/
166
157
def setToIfDefined (v : Option [U ]): T => T = v.fold((obj : T ) => obj)(setTo)
167
158
168
- /**
169
- * see [[PathModify.setToIf ]]
159
+ /** see [[PathModify.setToIf ]]
170
160
*/
171
161
def setToIf (condition : Boolean )(v : => U ): T => T =
172
162
if (condition) setTo(v)
173
163
else obj => obj
174
164
175
- /**
176
- * see [[AbstractPathModifyPimp ]]
165
+ /** see [[AbstractPathModifyPimp ]]
177
166
*/
178
167
def andThenModify [V ](f2 : PathLazyModify [U , V ]): PathLazyModify [T , V ] =
179
168
PathLazyModify [T , V ]((t, vv) => self.doModify(t, u => f2.doModify(u, vv)))
@@ -213,8 +202,8 @@ package object quicklens extends LowPriorityImplicits {
213
202
def index : T = sys.error(" " )
214
203
}
215
204
216
- implicit def traversableQuicklensFunctor [F [_], A ](
217
- implicit fac : Factory [A , F [A ]],
205
+ implicit def traversableQuicklensFunctor [F [_], A ](implicit
206
+ fac : Factory [A , F [A ]],
218
207
ev : F [A ] => Iterable [A ]
219
208
): QuicklensFunctor [F , A ] =
220
209
new QuicklensFunctor [F , A ] {
@@ -233,8 +222,8 @@ package object quicklens extends LowPriorityImplicits {
233
222
def index (fa : F [T ], idx : Int )(f : T => T ): F [T ]
234
223
}
235
224
236
- implicit class QuicklensMapAt [M [KT , TT ], K , T ](t : M [K , T ])(
237
- implicit f : QuicklensMapAtFunctor [M , K , T ]
225
+ implicit class QuicklensMapAt [M [KT , TT ], K , T ](t : M [K , T ])(implicit
226
+ f : QuicklensMapAtFunctor [M , K , T ]
238
227
) {
239
228
@ compileTimeOnly(canOnlyBeUsedInsideModify(" at" ))
240
229
def at (idx : K ): T = sys.error(" " )
@@ -256,8 +245,8 @@ package object quicklens extends LowPriorityImplicits {
256
245
def each (fa : F [K , T ])(f : T => T ): F [K , T ]
257
246
}
258
247
259
- implicit def mapQuicklensFunctor [M [KT , TT ] <: Map [KT , TT ], K , T ](
260
- implicit fac : Factory [(K , T ), M [K , T ]]
248
+ implicit def mapQuicklensFunctor [M [KT , TT ] <: Map [KT , TT ], K , T ](implicit
249
+ fac : Factory [(K , T ), M [K , T ]]
261
250
): QuicklensMapAtFunctor [M , K , T ] = new QuicklensMapAtFunctor [M , K , T ] {
262
251
override def at (fa : M [K , T ], key : K )(f : T => T ): M [K , T ] =
263
252
fa.updated(key, f(fa(key))).to(fac)
@@ -270,14 +259,14 @@ package object quicklens extends LowPriorityImplicits {
270
259
}
271
260
}
272
261
273
- implicit def seqQuicklensAtFunctor [F [_], T ](
274
- implicit fac : Factory [T , F [T ]],
262
+ implicit def seqQuicklensAtFunctor [F [_], T ](implicit
263
+ fac : Factory [T , F [T ]],
275
264
ev : F [T ] => Seq [T ]
276
265
): QuicklensAtFunctor [F , T ] =
277
266
new QuicklensAtFunctor [F , T ] {
278
- override def at (fa : F [T ], idx : Int )(f : T => T ): F [T ] =
267
+ override def at (fa : F [T ], idx : Int )(f : T => T ): F [T ] =
279
268
fa.updated(idx, f(fa(idx))).to(fac)
280
- override def index (fa : F [T ], idx : Int )(f : T => T ): F [T ] =
269
+ override def index (fa : F [T ], idx : Int )(f : T => T ): F [T ] =
281
270
if (idx < fa.size) fa.updated(idx, f(fa(idx))).to(fac) else fa
282
271
}
283
272
@@ -310,8 +299,7 @@ sealed trait LowPriorityImplicits {
310
299
311
300
import quicklens ._
312
301
313
- /**
314
- * `QuicklensEach` is in `LowPriorityImplicits` to not conflict with the `QuicklensMapAtFunctor` on `each` calls.
302
+ /** `QuicklensEach` is in `LowPriorityImplicits` to not conflict with the `QuicklensMapAtFunctor` on `each` calls.
315
303
*/
316
304
implicit class QuicklensEach [F [_], T ](t : F [T ])(implicit f : QuicklensFunctor [F , T ]) {
317
305
@ compileTimeOnly(canOnlyBeUsedInsideModify(" each" ))
0 commit comments