-
Notifications
You must be signed in to change notification settings - Fork 272
/
Control-Lens-Traversal.html
558 lines (558 loc) · 89.9 KB
/
Control-Lens-Traversal.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>src/Control/Lens/Traversal.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-# LANGUAGE MagicHash #-}</span>
<a name="line-2"></a><span class='hs-comment'>{-# LANGUAGE Rank2Types #-}</span>
<a name="line-3"></a><span class='hs-comment'>{-# LANGUAGE TypeOperators #-}</span>
<a name="line-4"></a><span class='hs-comment'>{-# LANGUAGE LiberalTypeSynonyms #-}</span>
<a name="line-5"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-6"></a><span class='hs-comment'>-- |</span>
<a name="line-7"></a><span class='hs-comment'>-- Module : Control.Lens.Traversal</span>
<a name="line-8"></a><span class='hs-comment'>-- Copyright : (C) 2012 Edward Kmett</span>
<a name="line-9"></a><span class='hs-comment'>-- License : BSD-style (see the file LICENSE)</span>
<a name="line-10"></a><span class='hs-comment'>-- Maintainer : Edward Kmett <ekmett@gmail.com></span>
<a name="line-11"></a><span class='hs-comment'>-- Stability : provisional</span>
<a name="line-12"></a><span class='hs-comment'>-- Portability : Rank2Types</span>
<a name="line-13"></a><span class='hs-comment'>--</span>
<a name="line-14"></a><span class='hs-comment'>-- A @'Traversal' s t a b@ is a generalization of 'traverse' from</span>
<a name="line-15"></a><span class='hs-comment'>-- 'Traversable'. It allows you to traverse over a structure and change out</span>
<a name="line-16"></a><span class='hs-comment'>-- its contents with monadic or applicative side-effects. Starting from</span>
<a name="line-17"></a><span class='hs-comment'>--</span>
<a name="line-18"></a><span class='hs-comment'>-- @'traverse' :: ('Traversable' t, 'Applicative' f) => (a -> f b) -> t a -> f (t b)@</span>
<a name="line-19"></a><span class='hs-comment'>--</span>
<a name="line-20"></a><span class='hs-comment'>-- we monomorphize the contents and result to obtain</span>
<a name="line-21"></a><span class='hs-comment'>--</span>
<a name="line-22"></a><span class='hs-comment'>-- @type 'Traversal' s t a b = forall f. 'Applicative' f => (a -> f b) -> s -> f t@</span>
<a name="line-23"></a><span class='hs-comment'>--</span>
<a name="line-24"></a><span class='hs-comment'>-- While a 'Traversal' isn't quite a 'Fold', it _can_ be used for 'Getting'</span>
<a name="line-25"></a><span class='hs-comment'>-- like a 'Fold', because given a 'Monoid' @m@, we have an 'Applicative'</span>
<a name="line-26"></a><span class='hs-comment'>-- for @('Const' m)@. Everything you know how to do with a 'Traversable'</span>
<a name="line-27"></a><span class='hs-comment'>-- container, you can with with a 'Traversal', and here we provide</span>
<a name="line-28"></a><span class='hs-comment'>-- combinators that generalize the usual 'Traversable' operations.</span>
<a name="line-29"></a><span class='hs-comment'>----------------------------------------------------------------------------</span>
<a name="line-30"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span><span class='hs-varop'>.</span><span class='hs-conid'>Traversal</span>
<a name="line-31"></a> <span class='hs-layout'>(</span>
<a name="line-32"></a> <span class='hs-comment'>-- * Lenses</span>
<a name="line-33"></a> <span class='hs-conid'>Traversal</span>
<a name="line-34"></a>
<a name="line-35"></a> <span class='hs-comment'>-- * Traversing and Lensing</span>
<a name="line-36"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>traverseOf</span><span class='hs-layout'>,</span> <span class='hs-varid'>forOf</span><span class='hs-layout'>,</span> <span class='hs-varid'>sequenceAOf</span>
<a name="line-37"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>mapMOf</span><span class='hs-layout'>,</span> <span class='hs-varid'>forMOf</span><span class='hs-layout'>,</span> <span class='hs-varid'>sequenceOf</span>
<a name="line-38"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>transposeOf</span>
<a name="line-39"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>mapAccumLOf</span><span class='hs-layout'>,</span> <span class='hs-varid'>mapAccumROf</span>
<a name="line-40"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>scanr1Of</span><span class='hs-layout'>,</span> <span class='hs-varid'>scanl1Of</span>
<a name="line-41"></a>
<a name="line-42"></a> <span class='hs-comment'>-- * Parts and Holes</span>
<a name="line-43"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>partsOf</span>
<a name="line-44"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>partsOf'</span>
<a name="line-45"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>unsafePartsOf</span>
<a name="line-46"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>unsafePartsOf'</span>
<a name="line-47"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>holesOf</span>
<a name="line-48"></a>
<a name="line-49"></a> <span class='hs-comment'>-- * Common Traversals</span>
<a name="line-50"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>Traversable</span><span class='hs-layout'>(</span><span class='hs-varid'>traverse</span><span class='hs-layout'>)</span>
<a name="line-51"></a> <span class='hs-layout'>,</span> <span class='hs-sel'>_left</span>
<a name="line-52"></a> <span class='hs-layout'>,</span> <span class='hs-sel'>_right</span>
<a name="line-53"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>both</span>
<a name="line-54"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>beside</span>
<a name="line-55"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>taking</span>
<a name="line-56"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>dropping</span>
<a name="line-57"></a>
<a name="line-58"></a> <span class='hs-comment'>-- * Cloning Traversals</span>
<a name="line-59"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>cloneTraversal</span>
<a name="line-60"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>ReifiedTraversal</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
<a name="line-61"></a>
<a name="line-62"></a> <span class='hs-comment'>-- * Simple</span>
<a name="line-63"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>SimpleTraversal</span>
<a name="line-64"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>SimpleReifiedTraversal</span>
<a name="line-65"></a>
<a name="line-66"></a> <span class='hs-comment'>-- * Exposed Implementation Details</span>
<a name="line-67"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>Bazaar</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
<a name="line-68"></a> <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-69"></a>
<a name="line-70"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Applicative</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Applicative</span>
<a name="line-71"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Applicative</span><span class='hs-varop'>.</span><span class='hs-conid'>Backwards</span>
<a name="line-72"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span><span class='hs-varop'>.</span><span class='hs-conid'>Fold</span>
<a name="line-73"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span>
<a name="line-74"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span><span class='hs-varop'>.</span><span class='hs-conid'>Combinators</span>
<a name="line-75"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Lens</span><span class='hs-varop'>.</span><span class='hs-conid'>Type</span>
<a name="line-76"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span><span class='hs-varop'>.</span><span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-conid'>Class</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>State</span>
<a name="line-77"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span><span class='hs-varop'>.</span><span class='hs-conid'>Trans</span><span class='hs-varop'>.</span><span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-conid'>Lazy</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Lazy</span>
<a name="line-78"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Traversable</span>
<a name="line-79"></a>
<a name="line-80"></a>
<a name="line-81"></a><span class='hs-comment'>-- $setup</span>
<a name="line-82"></a><span class='hs-comment'>-- >>> import Control.Lens</span>
<a name="line-83"></a>
<a name="line-84"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-85"></a><span class='hs-comment'>-- Traversals</span>
<a name="line-86"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-87"></a>
<a name="line-88"></a><a name="Traversal"></a><span class='hs-comment'>-- | A 'Traversal' can be used directly as a 'Control.Lens.Setter.Setter' or a 'Fold' (but not as a 'Lens') and provides</span>
<a name="line-89"></a><a name="Traversal"></a><span class='hs-comment'>-- the ability to both read and update multiple fields, subject to some relatively weak 'Traversal' laws.</span>
<a name="line-90"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-91"></a><a name="Traversal"></a><span class='hs-comment'>-- These have also been known as multilenses, but they have the signature and spirit of</span>
<a name="line-92"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-93"></a><a name="Traversal"></a><span class='hs-comment'>-- @'traverse' :: 'Traversable' f => 'Traversal' (f a) (f b) a b@</span>
<a name="line-94"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-95"></a><a name="Traversal"></a><span class='hs-comment'>-- and the more evocative name suggests their application.</span>
<a name="line-96"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-97"></a><a name="Traversal"></a><span class='hs-comment'>-- Most of the time the 'Traversal' you will want to use is just 'traverse', but you can also pass any</span>
<a name="line-98"></a><a name="Traversal"></a><span class='hs-comment'>-- 'Lens' or 'Control.Lens.Iso.Iso' as a 'Traversal', and composition of a 'Traversal' (or 'Lens' or 'Control.Lens.Iso.Iso') with a 'Traversal' (or 'Lens' or 'Control.Lens.Iso.Iso')</span>
<a name="line-99"></a><a name="Traversal"></a><span class='hs-comment'>-- using (.) forms a valid 'Traversal'.</span>
<a name="line-100"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-101"></a><a name="Traversal"></a><span class='hs-comment'>-- The laws for a Traversal @t@ follow from the laws for Traversable as stated in \"The Essence of the Iterator Pattern\".</span>
<a name="line-102"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-103"></a><a name="Traversal"></a><span class='hs-comment'>-- @</span>
<a name="line-104"></a><a name="Traversal"></a><span class='hs-comment'>-- t 'pure' ≡ 'pure'</span>
<a name="line-105"></a><a name="Traversal"></a><span class='hs-comment'>-- 'fmap' (t f) '.' t g ≡ 'Data.Functor.Compose.getCompose' '.' t ('Data.Functor.Compose.Compose' '.' 'fmap' f '.' g)</span>
<a name="line-106"></a><a name="Traversal"></a><span class='hs-comment'>-- @</span>
<a name="line-107"></a><a name="Traversal"></a><span class='hs-comment'>--</span>
<a name="line-108"></a><a name="Traversal"></a><span class='hs-comment'>-- One consequence of this requirement is that a 'Traversal' needs to leave the same number of elements as a</span>
<a name="line-109"></a><a name="Traversal"></a><span class='hs-comment'>-- candidate for subsequent 'Traversal' that it started with. Another testament to the strength of these laws</span>
<a name="line-110"></a><a name="Traversal"></a><span class='hs-comment'>-- is that the caveat expressed in section 5.5 of the \"Essence of the Iterator Pattern\" about exotic</span>
<a name="line-111"></a><a name="Traversal"></a><span class='hs-comment'>-- 'Traversable' instances that 'traverse' the same entry multiple times was actually already ruled out by the</span>
<a name="line-112"></a><a name="Traversal"></a><span class='hs-comment'>-- second law in that same paper!</span>
<a name="line-113"></a><a name="Traversal"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Traversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>f</span><span class='hs-varop'>.</span> <span class='hs-conid'>Applicative</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span>
<a name="line-114"></a>
<a name="line-115"></a><a name="SimpleTraversal"></a><span class='hs-comment'>-- | @type SimpleTraversal = 'Simple' 'Traversal'@</span>
<a name="line-116"></a><a name="SimpleTraversal"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>SimpleTraversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Traversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span>
<a name="line-117"></a>
<a name="line-118"></a><span class='hs-comment'>--------------------------</span>
<a name="line-119"></a><span class='hs-comment'>-- Traversal Combinators</span>
<a name="line-120"></a><span class='hs-comment'>--------------------------</span>
<a name="line-121"></a>
<a name="line-122"></a><a name="traverseOf"></a><span class='hs-comment'>-- |</span>
<a name="line-123"></a><span class='hs-comment'>-- Map each element of a structure targeted by a Lens or Traversal,</span>
<a name="line-124"></a><span class='hs-comment'>-- evaluate these actions from left to right, and collect the results.</span>
<a name="line-125"></a><span class='hs-comment'>--</span>
<a name="line-126"></a><span class='hs-comment'>-- This function is only provided for consistency, 'id' is strictly more general.</span>
<a name="line-127"></a><span class='hs-comment'>--</span>
<a name="line-128"></a><span class='hs-comment'>-- @'traverseOf' ≡ 'id'@</span>
<a name="line-129"></a><span class='hs-comment'>--</span>
<a name="line-130"></a><span class='hs-comment'>-- This yields the obvious law:</span>
<a name="line-131"></a><span class='hs-comment'>--</span>
<a name="line-132"></a><span class='hs-comment'>-- @'traverse' ≡ 'traverseOf' 'traverse'@</span>
<a name="line-133"></a><span class='hs-comment'>--</span>
<a name="line-134"></a><span class='hs-comment'>-- @</span>
<a name="line-135"></a><span class='hs-comment'>-- 'traverseOf' :: 'Control.Lens.Iso.Iso' s t a b -> (a -> f b) -> s -> f t</span>
<a name="line-136"></a><span class='hs-comment'>-- 'traverseOf' :: 'Lens' s t a b -> (a -> f b) -> s -> f t</span>
<a name="line-137"></a><span class='hs-comment'>-- 'traverseOf' :: 'Traversal' s t a b -> (a -> f b) -> s -> f t</span>
<a name="line-138"></a><span class='hs-comment'>-- @</span>
<a name="line-139"></a><span class='hs-definition'>traverseOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span>
<a name="line-140"></a><span class='hs-definition'>traverseOf</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>id</span>
<a name="line-141"></a><span class='hs-comment'>{-# INLINE traverseOf #-}</span>
<a name="line-142"></a>
<a name="line-143"></a><a name="forOf"></a><span class='hs-comment'>-- | A version of 'traverseOf' with the arguments flipped, such that:</span>
<a name="line-144"></a><span class='hs-comment'>--</span>
<a name="line-145"></a><span class='hs-comment'>-- @'forOf' l ≡ 'flip' ('traverseOf' l)@</span>
<a name="line-146"></a><span class='hs-comment'>--</span>
<a name="line-147"></a><span class='hs-comment'>-- @</span>
<a name="line-148"></a><span class='hs-comment'>-- 'for' ≡ 'forOf' 'traverse'</span>
<a name="line-149"></a><span class='hs-comment'>-- @</span>
<a name="line-150"></a><span class='hs-comment'>--</span>
<a name="line-151"></a><span class='hs-comment'>-- This function is only provided for consistency, 'flip' is strictly more general.</span>
<a name="line-152"></a><span class='hs-comment'>--</span>
<a name="line-153"></a><span class='hs-comment'>-- @</span>
<a name="line-154"></a><span class='hs-comment'>-- 'forOf' ≡ 'flip'</span>
<a name="line-155"></a><span class='hs-comment'>-- @</span>
<a name="line-156"></a><span class='hs-comment'>--</span>
<a name="line-157"></a><span class='hs-comment'>-- @</span>
<a name="line-158"></a><span class='hs-comment'>-- 'forOf' :: 'Control.Lens.Iso.Iso' s t a b -> s -> (a -> f b) -> f t</span>
<a name="line-159"></a><span class='hs-comment'>-- 'forOf' :: 'Lens' s t a b -> s -> (a -> f b) -> f t</span>
<a name="line-160"></a><span class='hs-comment'>-- 'forOf' :: 'Traversal' s t a b -> s -> (a -> f b) -> f t</span>
<a name="line-161"></a><span class='hs-comment'>-- @</span>
<a name="line-162"></a><span class='hs-definition'>forOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span>
<a name="line-163"></a><span class='hs-definition'>forOf</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>flip</span>
<a name="line-164"></a><span class='hs-comment'>{-# INLINE forOf #-}</span>
<a name="line-165"></a>
<a name="line-166"></a><a name="sequenceAOf"></a><span class='hs-comment'>-- |</span>
<a name="line-167"></a><span class='hs-comment'>-- Evaluate each action in the structure from left to right, and collect</span>
<a name="line-168"></a><span class='hs-comment'>-- the results.</span>
<a name="line-169"></a><span class='hs-comment'>--</span>
<a name="line-170"></a><span class='hs-comment'>-- @</span>
<a name="line-171"></a><span class='hs-comment'>-- 'sequenceA' ≡ 'sequenceAOf' 'traverse' ≡ 'traverse' 'id'</span>
<a name="line-172"></a><span class='hs-comment'>-- 'sequenceAOf' l ≡ 'traverseOf' l id ≡ l id</span>
<a name="line-173"></a><span class='hs-comment'>-- @</span>
<a name="line-174"></a><span class='hs-comment'>--</span>
<a name="line-175"></a><span class='hs-comment'>-- @</span>
<a name="line-176"></a><span class='hs-comment'>-- 'sequenceAOf' :: 'Control.Lens.Iso.Iso' s t (f b) b -> s -> f t</span>
<a name="line-177"></a><span class='hs-comment'>-- 'sequenceAOf' :: 'Lens' s t (f b) b -> s -> f t</span>
<a name="line-178"></a><span class='hs-comment'>-- 'sequenceAOf' :: 'Applicative' f => 'Traversal' s t (f b) b -> s -> f t</span>
<a name="line-179"></a><span class='hs-comment'>-- @</span>
<a name="line-180"></a><span class='hs-definition'>sequenceAOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span>
<a name="line-181"></a><span class='hs-definition'>sequenceAOf</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>id</span>
<a name="line-182"></a><span class='hs-comment'>{-# INLINE sequenceAOf #-}</span>
<a name="line-183"></a>
<a name="line-184"></a><a name="mapMOf"></a><span class='hs-comment'>-- | Map each element of a structure targeted by a lens to a monadic action,</span>
<a name="line-185"></a><span class='hs-comment'>-- evaluate these actions from left to right, and collect the results.</span>
<a name="line-186"></a><span class='hs-comment'>--</span>
<a name="line-187"></a><span class='hs-comment'>-- @'mapM' ≡ 'mapMOf' 'traverse'@</span>
<a name="line-188"></a><span class='hs-comment'>--</span>
<a name="line-189"></a><span class='hs-comment'>-- @</span>
<a name="line-190"></a><span class='hs-comment'>-- 'mapMOf' :: 'Control.Lens.Iso.Iso' s t a b -> (a -> m b) -> s -> m t</span>
<a name="line-191"></a><span class='hs-comment'>-- 'mapMOf' :: 'Lens' s t a b -> (a -> m b) -> s -> m t</span>
<a name="line-192"></a><span class='hs-comment'>-- 'mapMOf' :: 'Monad' m => 'Traversal' s t a b -> (a -> m b) -> s -> m t</span>
<a name="line-193"></a><span class='hs-comment'>-- @</span>
<a name="line-194"></a><span class='hs-definition'>mapMOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>WrappedMonad</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>t</span>
<a name="line-195"></a><span class='hs-definition'>mapMOf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>cmd</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrapMonad</span><span class='hs-cpp'>#</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrapMonad</span><span class='hs-cpp'>#</span> <span class='hs-varid'>cmd</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-196"></a><span class='hs-comment'>{-# INLINE mapMOf #-}</span>
<a name="line-197"></a>
<a name="line-198"></a><a name="forMOf"></a><span class='hs-comment'>-- | 'forMOf' is a flipped version of 'mapMOf', consistent with the definition of 'forM'.</span>
<a name="line-199"></a><span class='hs-comment'>-- @</span>
<a name="line-200"></a><span class='hs-comment'>-- 'forM' ≡ 'forMOf' 'traverse'</span>
<a name="line-201"></a><span class='hs-comment'>-- 'forMOf' l ≡ 'flip' ('mapMOf' l)</span>
<a name="line-202"></a><span class='hs-comment'>-- @</span>
<a name="line-203"></a><span class='hs-comment'>--</span>
<a name="line-204"></a><span class='hs-comment'>-- @</span>
<a name="line-205"></a><span class='hs-comment'>-- 'forMOf' :: 'Control.Lens.Iso.Iso' s t a b -> s -> (a -> m b) -> m t</span>
<a name="line-206"></a><span class='hs-comment'>-- 'forMOf' :: 'Lens' s t a b -> s -> (a -> m b) -> m t</span>
<a name="line-207"></a><span class='hs-comment'>-- 'forMOf' :: 'Monad' m => 'Traversal' s t a b -> s -> (a -> m b) -> m t</span>
<a name="line-208"></a><span class='hs-comment'>-- @</span>
<a name="line-209"></a><span class='hs-definition'>forMOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>WrappedMonad</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>t</span>
<a name="line-210"></a><span class='hs-definition'>forMOf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>a</span> <span class='hs-varid'>cmd</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrapMonad</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrapMonad</span><span class='hs-cpp'>#</span> <span class='hs-varid'>cmd</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-211"></a><span class='hs-comment'>{-# INLINE forMOf #-}</span>
<a name="line-212"></a>
<a name="line-213"></a><a name="sequenceOf"></a><span class='hs-comment'>-- | Sequence the (monadic) effects targeted by a lens in a container from left to right.</span>
<a name="line-214"></a><span class='hs-comment'>--</span>
<a name="line-215"></a><span class='hs-comment'>-- @</span>
<a name="line-216"></a><span class='hs-comment'>-- 'sequence' ≡ 'sequenceOf' 'traverse'</span>
<a name="line-217"></a><span class='hs-comment'>-- 'sequenceOf' l ≡ 'mapMOf' l id</span>
<a name="line-218"></a><span class='hs-comment'>-- 'sequenceOf' l ≡ 'unwrapMonad' . l 'WrapMonad'</span>
<a name="line-219"></a><span class='hs-comment'>-- @</span>
<a name="line-220"></a><span class='hs-comment'>--</span>
<a name="line-221"></a><span class='hs-comment'>-- @</span>
<a name="line-222"></a><span class='hs-comment'>-- 'sequenceOf' :: 'Control.Lens.Iso.Iso' s t (m b) b -> s -> m t</span>
<a name="line-223"></a><span class='hs-comment'>-- 'sequenceOf' :: 'Lens' s t (m b) b -> s -> m t</span>
<a name="line-224"></a><span class='hs-comment'>-- 'sequenceOf' :: 'Monad' m => 'Traversal' s t (m b) b -> s -> m t</span>
<a name="line-225"></a><span class='hs-comment'>-- @</span>
<a name="line-226"></a><span class='hs-definition'>sequenceOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>WrappedMonad</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>t</span>
<a name="line-227"></a><span class='hs-definition'>sequenceOf</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrapMonad</span><span class='hs-cpp'>#</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-conid'>WrapMonad</span><span class='hs-layout'>)</span>
<a name="line-228"></a><span class='hs-comment'>{-# INLINE sequenceOf #-}</span>
<a name="line-229"></a>
<a name="line-230"></a><a name="transposeOf"></a><span class='hs-comment'>-- | This generalizes 'Data.List.transpose' to an arbitrary 'Traversal'.</span>
<a name="line-231"></a><span class='hs-comment'>--</span>
<a name="line-232"></a><span class='hs-comment'>-- Note: 'Data.List.transpose' handles ragged inputs more intelligently, but for non-ragged inputs:</span>
<a name="line-233"></a><span class='hs-comment'>--</span>
<a name="line-234"></a><span class='hs-comment'>-- @'Data.List.transpose' ≡ 'transposeOf' 'traverse'@</span>
<a name="line-235"></a><span class='hs-comment'>--</span>
<a name="line-236"></a><span class='hs-comment'>-- >>> transposeOf traverse [[1,2,3],[4,5,6]]</span>
<a name="line-237"></a><span class='hs-comment'>-- [[1,4],[2,5],[3,6]]</span>
<a name="line-238"></a><span class='hs-comment'>--</span>
<a name="line-239"></a><span class='hs-comment'>-- Since every 'Lens' is a 'Traversal', we can use this as a form of</span>
<a name="line-240"></a><span class='hs-comment'>-- monadic strength as well:</span>
<a name="line-241"></a><span class='hs-comment'>--</span>
<a name="line-242"></a><span class='hs-comment'>-- @'transposeOf' '_2' :: (b, [a]) -> [(b, a)]@</span>
<a name="line-243"></a><span class='hs-definition'>transposeOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-conid'>ZipList</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>t</span><span class='hs-keyglyph'>]</span>
<a name="line-244"></a><span class='hs-definition'>transposeOf</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>getZipList</span><span class='hs-cpp'>#</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-conid'>ZipList</span><span class='hs-layout'>)</span>
<a name="line-245"></a><span class='hs-comment'>{-# INLINE transposeOf #-}</span>
<a name="line-246"></a>
<a name="line-247"></a><a name="mapAccumROf"></a><span class='hs-comment'>-- | This generalizes 'Data.Traversable.mapAccumR' to an arbitrary 'Traversal'.</span>
<a name="line-248"></a><span class='hs-comment'>--</span>
<a name="line-249"></a><span class='hs-comment'>-- @'mapAccumR' ≡ 'mapAccumROf' 'traverse'@</span>
<a name="line-250"></a><span class='hs-comment'>--</span>
<a name="line-251"></a><span class='hs-comment'>-- 'mapAccumROf' accumulates state from right to left.</span>
<a name="line-252"></a><span class='hs-comment'>--</span>
<a name="line-253"></a><span class='hs-comment'>-- @</span>
<a name="line-254"></a><span class='hs-comment'>-- 'mapAccumROf' :: 'Control.Lens.Iso.Iso' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)</span>
<a name="line-255"></a><span class='hs-comment'>-- 'mapAccumROf' :: 'Lens' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)</span>
<a name="line-256"></a><span class='hs-comment'>-- 'mapAccumROf' :: 'Traversal' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)</span>
<a name="line-257"></a><span class='hs-comment'>-- @</span>
<a name="line-258"></a><span class='hs-definition'>mapAccumROf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lazy</span><span class='hs-varop'>.</span><span class='hs-conid'>State</span> <span class='hs-varid'>acc</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>acc</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>acc</span><span class='hs-layout'>,</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>acc</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>acc</span><span class='hs-layout'>,</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span>
<a name="line-259"></a><span class='hs-definition'>mapAccumROf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s0</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>swap</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lazy</span><span class='hs-varop'>.</span><span class='hs-varid'>runState</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>c</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-varid'>state</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>swap</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>s0</span><span class='hs-layout'>)</span>
<a name="line-260"></a><span class='hs-comment'>{-# INLINE mapAccumROf #-}</span>
<a name="line-261"></a>
<a name="line-262"></a><a name="mapAccumLOf"></a><span class='hs-comment'>-- | This generalizes 'Data.Traversable.mapAccumL' to an arbitrary 'Traversal'.</span>
<a name="line-263"></a><span class='hs-comment'>--</span>
<a name="line-264"></a><span class='hs-comment'>-- @'mapAccumL' ≡ 'mapAccumLOf' 'traverse'@</span>
<a name="line-265"></a><span class='hs-comment'>--</span>
<a name="line-266"></a><span class='hs-comment'>-- 'mapAccumLOf' accumulates state from left to right.</span>
<a name="line-267"></a><span class='hs-comment'>--</span>
<a name="line-268"></a><span class='hs-comment'>-- @</span>
<a name="line-269"></a><span class='hs-comment'>-- 'mapAccumLOf' :: 'Control.Lens.Iso.Iso' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)</span>
<a name="line-270"></a><span class='hs-comment'>-- 'mapAccumLOf' :: 'Lens' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)</span>
<a name="line-271"></a><span class='hs-comment'>-- 'mapAccumLOf' :: 'Traversal' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)</span>
<a name="line-272"></a><span class='hs-comment'>-- @</span>
<a name="line-273"></a><span class='hs-definition'>mapAccumLOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Backwards</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lazy</span><span class='hs-varop'>.</span><span class='hs-conid'>State</span> <span class='hs-varid'>acc</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>acc</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>acc</span><span class='hs-layout'>,</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>acc</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>acc</span><span class='hs-layout'>,</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span>
<a name="line-274"></a><span class='hs-definition'>mapAccumLOf</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mapAccumROf</span> <span class='hs-varop'>.</span> <span class='hs-varid'>backwards</span>
<a name="line-275"></a><span class='hs-comment'>{-# INLINE mapAccumLOf #-}</span>
<a name="line-276"></a>
<a name="line-277"></a><a name="swap"></a><span class='hs-definition'>swap</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-278"></a><span class='hs-definition'>swap</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-279"></a><span class='hs-comment'>{-# INLINE swap #-}</span>
<a name="line-280"></a>
<a name="line-281"></a><a name="scanr1Of"></a><span class='hs-comment'>-- | This permits the use of 'scanr1' over an arbitrary 'Traversal' or 'Lens'.</span>
<a name="line-282"></a><span class='hs-comment'>--</span>
<a name="line-283"></a><span class='hs-comment'>-- @'scanr1' ≡ 'scanr1Of' 'traverse'@</span>
<a name="line-284"></a><span class='hs-comment'>--</span>
<a name="line-285"></a><span class='hs-comment'>-- @</span>
<a name="line-286"></a><span class='hs-comment'>-- 'scanr1Of' :: 'Control.Lens.Iso.Iso' s t a a -> (a -> a -> a) -> s -> t</span>
<a name="line-287"></a><span class='hs-comment'>-- 'scanr1Of' :: 'Lens' s t a a -> (a -> a -> a) -> s -> t</span>
<a name="line-288"></a><span class='hs-comment'>-- 'scanr1Of' :: 'Traversal' s t a a -> (a -> a -> a) -> s -> t</span>
<a name="line-289"></a><span class='hs-comment'>-- @</span>
<a name="line-290"></a><span class='hs-definition'>scanr1Of</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lazy</span><span class='hs-varop'>.</span><span class='hs-conid'>State</span> <span class='hs-layout'>(</span><span class='hs-conid'>Maybe</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>t</span>
<a name="line-291"></a><span class='hs-definition'>scanr1Of</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>snd</span> <span class='hs-varop'>.</span> <span class='hs-varid'>mapAccumROf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>step</span> <span class='hs-conid'>Nothing</span> <span class='hs-keyword'>where</span>
<a name="line-292"></a> <span class='hs-varid'>step</span> <span class='hs-conid'>Nothing</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-293"></a> <span class='hs-varid'>step</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>r</span><span class='hs-layout'>,</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>r</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>s</span>
<a name="line-294"></a><span class='hs-comment'>{-# INLINE scanr1Of #-}</span>
<a name="line-295"></a>
<a name="line-296"></a><a name="scanl1Of"></a><span class='hs-comment'>-- | This permits the use of 'scanl1' over an arbitrary 'Traversal' or 'Lens'.</span>
<a name="line-297"></a><span class='hs-comment'>--</span>
<a name="line-298"></a><span class='hs-comment'>-- @'scanl1' ≡ 'scanl1Of' 'traverse'@</span>
<a name="line-299"></a><span class='hs-comment'>--</span>
<a name="line-300"></a><span class='hs-comment'>-- @</span>
<a name="line-301"></a><span class='hs-comment'>-- 'scanr1Of' :: 'Control.Lens.Iso.Iso' s t a a -> (a -> a -> a) -> s -> t</span>
<a name="line-302"></a><span class='hs-comment'>-- 'scanr1Of' :: 'Lens' s t a a -> (a -> a -> a) -> s -> t</span>
<a name="line-303"></a><span class='hs-comment'>-- 'scanr1Of' :: 'Traversal' s t a a -> (a -> a -> a) -> s -> t</span>
<a name="line-304"></a><span class='hs-comment'>-- @</span>
<a name="line-305"></a><span class='hs-definition'>scanl1Of</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Backwards</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lazy</span><span class='hs-varop'>.</span><span class='hs-conid'>State</span> <span class='hs-layout'>(</span><span class='hs-conid'>Maybe</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>t</span>
<a name="line-306"></a><span class='hs-definition'>scanl1Of</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>snd</span> <span class='hs-varop'>.</span> <span class='hs-varid'>mapAccumLOf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>step</span> <span class='hs-conid'>Nothing</span> <span class='hs-keyword'>where</span>
<a name="line-307"></a> <span class='hs-varid'>step</span> <span class='hs-conid'>Nothing</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-308"></a> <span class='hs-varid'>step</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>r</span><span class='hs-layout'>,</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>r</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span>
<a name="line-309"></a><span class='hs-comment'>{-# INLINE scanl1Of #-}</span>
<a name="line-310"></a>
<a name="line-311"></a><span class='hs-comment'>-------------------------------------------------------------------------------</span>
<a name="line-312"></a><span class='hs-comment'>-- Parts and Holes</span>
<a name="line-313"></a><span class='hs-comment'>-------------------------------------------------------------------------------</span>
<a name="line-314"></a>
<a name="line-315"></a><a name="partsOf"></a><span class='hs-comment'>-- | 'partsOf' turns a 'Traversal' into a 'Lens' that resembles an early version of the @uniplate@ (or @biplate@) type.</span>
<a name="line-316"></a><span class='hs-comment'>--</span>
<a name="line-317"></a><span class='hs-comment'>-- /Note:/ You should really try to maintain the invariant of the number of children in the list.</span>
<a name="line-318"></a><span class='hs-comment'>--</span>
<a name="line-319"></a><span class='hs-comment'>-- Any extras will be lost. If you do not supply enough, then the remainder will come from the original structure.</span>
<a name="line-320"></a><span class='hs-comment'>--</span>
<a name="line-321"></a><span class='hs-comment'>-- So technically, this is only a lens if you do not change the number of results it returns.</span>
<a name="line-322"></a><span class='hs-comment'>--</span>
<a name="line-323"></a><span class='hs-comment'>-- When applied to a 'Fold' the result is merely a 'Getter'.</span>
<a name="line-324"></a><span class='hs-comment'>--</span>
<a name="line-325"></a><span class='hs-comment'>-- @</span>
<a name="line-326"></a><span class='hs-comment'>-- 'partsOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a -> 'Simple' 'Lens' s [a]</span>
<a name="line-327"></a><span class='hs-comment'>-- 'partsOf' :: 'Simple' 'Lens' s a -> 'Simple' 'Lens' s [a]</span>
<a name="line-328"></a><span class='hs-comment'>-- 'partsOf' :: 'Simple' 'Traversal' s a -> 'Simple' 'Lens' s [a]</span>
<a name="line-329"></a><span class='hs-comment'>-- 'partsOf' :: 'Fold' s a -> 'Getter' s [a]</span>
<a name="line-330"></a><span class='hs-comment'>-- 'partsOf' :: 'Getter' s a -> 'Getter' s [a]</span>
<a name="line-331"></a><span class='hs-comment'>-- @</span>
<a name="line-332"></a><span class='hs-definition'>partsOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Functor</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>BazaarT</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span>
<a name="line-333"></a><span class='hs-definition'>partsOf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>outsT</span> <span class='hs-varid'>b</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>insT</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sellT</span> <span class='hs-varid'>s</span>
<a name="line-334"></a><span class='hs-comment'>{-# INLINE partsOf #-}</span>
<a name="line-335"></a>
<a name="line-336"></a><a name="partsOf'"></a><span class='hs-comment'>-- | A type-restricted version of 'partsOf' that can only be used with a 'Traversal'.</span>
<a name="line-337"></a><span class='hs-definition'>partsOf'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Lens</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span>
<a name="line-338"></a><span class='hs-definition'>partsOf'</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>outs</span> <span class='hs-varid'>b</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>ins</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sell</span> <span class='hs-varid'>s</span>
<a name="line-339"></a><span class='hs-comment'>{-# INLINE partsOf' #-}</span>
<a name="line-340"></a>
<a name="line-341"></a><a name="unsafePartsOf"></a><span class='hs-comment'>-- | 'unsafePartsOf' turns a 'Traversal' into a @uniplate@ (or @biplate@) family.</span>
<a name="line-342"></a><span class='hs-comment'>--</span>
<a name="line-343"></a><span class='hs-comment'>-- If you do not need the types of @s@ and @t@ to be different, it is recommended that</span>
<a name="line-344"></a><span class='hs-comment'>-- you use 'partsOf'</span>
<a name="line-345"></a><span class='hs-comment'>--</span>
<a name="line-346"></a><span class='hs-comment'>-- It is generally safer to traverse with the 'Bazaar' rather than use this</span>
<a name="line-347"></a><span class='hs-comment'>-- combinator. However, it is sometimes convenient.</span>
<a name="line-348"></a><span class='hs-comment'>--</span>
<a name="line-349"></a><span class='hs-comment'>-- This is unsafe because if you don't supply at least as many @b@'s as you were</span>
<a name="line-350"></a><span class='hs-comment'>-- given @a@'s, then the reconstruction of @t@ /will/ result in an error!</span>
<a name="line-351"></a><span class='hs-comment'>--</span>
<a name="line-352"></a><span class='hs-comment'>-- When applied to a 'Fold' the result is merely a 'Getter' (and becomes safe).</span>
<a name="line-353"></a><span class='hs-comment'>--</span>
<a name="line-354"></a><span class='hs-comment'>-- @</span>
<a name="line-355"></a><span class='hs-comment'>-- 'unsafePartsOf' :: 'Control.Lens.Iso.Iso' s t a b -> 'Lens' s t [a] [b]</span>
<a name="line-356"></a><span class='hs-comment'>-- 'unsafePartsOf' :: 'Lens' s t a b -> 'Lens' s t [a] [b]</span>
<a name="line-357"></a><span class='hs-comment'>-- 'unsafePartsOf' :: 'Traversal' s t a b -> 'Lens' s t [a] [b]</span>
<a name="line-358"></a><span class='hs-comment'>-- 'unsafePartsOf' :: 'Fold' s a -> 'Getter' s [a]</span>
<a name="line-359"></a><span class='hs-comment'>-- 'unsafePartsOf' :: 'Getter' s a -> 'Getter' s [a]</span>
<a name="line-360"></a><span class='hs-comment'>-- @</span>
<a name="line-361"></a><span class='hs-definition'>unsafePartsOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Functor</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>BazaarT</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span>
<a name="line-362"></a><span class='hs-definition'>unsafePartsOf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafeOutsT</span> <span class='hs-varid'>b</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>insT</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sellT</span> <span class='hs-varid'>s</span>
<a name="line-363"></a><span class='hs-comment'>{-# INLINE unsafePartsOf #-}</span>
<a name="line-364"></a>
<a name="line-365"></a><a name="unsafePartsOf'"></a><span class='hs-definition'>unsafePartsOf'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Lens</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span>
<a name="line-366"></a><span class='hs-definition'>unsafePartsOf'</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafeOuts</span> <span class='hs-varid'>b</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>ins</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sell</span> <span class='hs-varid'>s</span>
<a name="line-367"></a><span class='hs-comment'>{-# INLINE unsafePartsOf' #-}</span>
<a name="line-368"></a>
<a name="line-369"></a><a name="holesOf"></a><span class='hs-comment'>-- | The one-level version of 'contextsOf'. This extracts a list of the immediate children according to a given 'Traversal' as editable contexts.</span>
<a name="line-370"></a><span class='hs-comment'>--</span>
<a name="line-371"></a><span class='hs-comment'>-- Given a context you can use 'pos' to see the values, 'peek' at what the structure would be like with an edited result, or simply 'extract' the original structure.</span>
<a name="line-372"></a><span class='hs-comment'>--</span>
<a name="line-373"></a><span class='hs-comment'>-- @</span>
<a name="line-374"></a><span class='hs-comment'>-- propChildren l x = 'childrenOf' l x '==' 'map' 'pos' ('holesOf' l x)</span>
<a name="line-375"></a><span class='hs-comment'>-- propId l x = 'all' ('==' x) [extract w | w <- 'holesOf' l x]</span>
<a name="line-376"></a><span class='hs-comment'>-- @</span>
<a name="line-377"></a><span class='hs-comment'>--</span>
<a name="line-378"></a><span class='hs-comment'>-- @</span>
<a name="line-379"></a><span class='hs-comment'>-- 'holesOf' :: 'Simple' 'Iso' s a -> s -> ['Context' a a s]</span>
<a name="line-380"></a><span class='hs-comment'>-- 'holesOf' :: 'Simple' 'Lens' s a -> s -> ['Context' a a s]</span>
<a name="line-381"></a><span class='hs-comment'>-- 'holesOf' :: 'Simple' 'Traversal' s a -> s -> ['Context' a a s]</span>
<a name="line-382"></a><span class='hs-comment'>-- @</span>
<a name="line-383"></a><span class='hs-definition'>holesOf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Context</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-varid'>t</span><span class='hs-keyglyph'>]</span>
<a name="line-384"></a><span class='hs-definition'>holesOf</span> <span class='hs-varid'>l</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>ins</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>outs</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-385"></a> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sell</span> <span class='hs-varid'>a</span>
<a name="line-386"></a> <span class='hs-varid'>f</span> <span class='hs-conid'>[]</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>[]</span>
<a name="line-387"></a> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Context</span> <span class='hs-layout'>(</span><span class='hs-varid'>g</span> <span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-conop'>:</span> <span class='hs-varid'>f</span> <span class='hs-varid'>xs</span> <span class='hs-layout'>(</span><span class='hs-varid'>g</span> <span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-388"></a><span class='hs-comment'>{-# INLINE holesOf #-}</span>
<a name="line-389"></a>
<a name="line-390"></a><a name="ins"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-391"></a><span class='hs-comment'>-- Internal functions used by 'partsOf', 'holesOf', etc.</span>
<a name="line-392"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-393"></a><span class='hs-definition'>ins</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span>
<a name="line-394"></a><span class='hs-definition'>ins</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toListOf</span> <span class='hs-varid'>bazaar</span>
<a name="line-395"></a><span class='hs-comment'>{-# INLINE ins #-}</span>
<a name="line-396"></a>
<a name="line-397"></a><a name="outs"></a><span class='hs-definition'>outs</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>t</span>
<a name="line-398"></a><span class='hs-definition'>outs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>evalState</span> <span class='hs-varop'>.</span> <span class='hs-varid'>bazaar</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>oldVal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-varid'>state</span> <span class='hs-layout'>(</span><span class='hs-varid'>unconsWithDefault</span> <span class='hs-varid'>oldVal</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-399"></a><span class='hs-comment'>{-# INLINE outs #-}</span>
<a name="line-400"></a>
<a name="line-401"></a><a name="unsafeOuts"></a><span class='hs-definition'>unsafeOuts</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>t</span>
<a name="line-402"></a><span class='hs-definition'>unsafeOuts</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>evalState</span> <span class='hs-varop'>.</span> <span class='hs-varid'>bazaar</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-varid'>state</span> <span class='hs-layout'>(</span><span class='hs-varid'>unconsWithDefault</span> <span class='hs-varid'>fakeVal</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-403"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>fakeVal</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"unsafePartsOf': not enough elements were supplied"</span>
<a name="line-404"></a><span class='hs-comment'>{-# INLINE unsafeOuts #-}</span>
<a name="line-405"></a>
<a name="line-406"></a><a name="insT"></a><span class='hs-definition'>insT</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>BazaarT</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span>
<a name="line-407"></a><span class='hs-definition'>insT</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toListOf</span> <span class='hs-varid'>bazaarT</span>
<a name="line-408"></a><span class='hs-comment'>{-# INLINE insT #-}</span>
<a name="line-409"></a>
<a name="line-410"></a><a name="outsT"></a><span class='hs-definition'>outsT</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>BazaarT</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>t</span>
<a name="line-411"></a><span class='hs-definition'>outsT</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>evalState</span> <span class='hs-varop'>.</span> <span class='hs-varid'>bazaarT</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>oldVal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-varid'>state</span> <span class='hs-layout'>(</span><span class='hs-varid'>unconsWithDefault</span> <span class='hs-varid'>oldVal</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-412"></a><span class='hs-comment'>{-# INLINE outsT #-}</span>
<a name="line-413"></a>
<a name="line-414"></a><a name="unsafeOutsT"></a><span class='hs-definition'>unsafeOutsT</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>BazaarT</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>t</span>
<a name="line-415"></a><span class='hs-definition'>unsafeOutsT</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>evalState</span> <span class='hs-varop'>.</span> <span class='hs-varid'>bazaarT</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>State</span><span class='hs-varop'>.</span><span class='hs-varid'>state</span> <span class='hs-layout'>(</span><span class='hs-varid'>unconsWithDefault</span> <span class='hs-varid'>fakeVal</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-416"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>fakeVal</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"unsafePartsOf: not enough elements were supplied"</span>
<a name="line-417"></a><span class='hs-comment'>{-# INLINE unsafeOutsT #-}</span>
<a name="line-418"></a>
<a name="line-419"></a><a name="unconsWithDefault"></a><span class='hs-definition'>unconsWithDefault</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-420"></a><span class='hs-definition'>unconsWithDefault</span> <span class='hs-varid'>d</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>d</span><span class='hs-layout'>,</span><span class='hs-conid'>[]</span><span class='hs-layout'>)</span>
<a name="line-421"></a><span class='hs-definition'>unconsWithDefault</span> <span class='hs-keyword'>_</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span>
<a name="line-422"></a><span class='hs-comment'>{-# INLINE unconsWithDefault #-}</span>
<a name="line-423"></a>
<a name="line-424"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-425"></a><span class='hs-comment'>-- Traversals</span>
<a name="line-426"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-427"></a>
<a name="line-428"></a><a name="both"></a><span class='hs-comment'>-- | Traverse both parts of a tuple with matching types.</span>
<a name="line-429"></a><span class='hs-comment'>--</span>
<a name="line-430"></a><span class='hs-comment'>-- >>> both *~ 10 $ (1,2)</span>
<a name="line-431"></a><span class='hs-comment'>-- (10,20)</span>
<a name="line-432"></a><span class='hs-comment'>-- >>> over both length ("hello","world")</span>
<a name="line-433"></a><span class='hs-comment'>-- (5,5)</span>
<a name="line-434"></a><span class='hs-comment'>-- >>> ("hello","world")^.both</span>
<a name="line-435"></a><span class='hs-comment'>-- "helloworld"</span>
<a name="line-436"></a><span class='hs-definition'>both</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Traversal</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
<a name="line-437"></a><span class='hs-definition'>both</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>~</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>(,)</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varop'><*></span> <span class='hs-varid'>f</span> <span class='hs-varid'>a'</span>
<a name="line-438"></a><span class='hs-comment'>{-# INLINE both #-}</span>
<a name="line-439"></a>
<a name="line-440"></a><a name="beside"></a><span class='hs-comment'>-- | Apply a different 'Traversal' or 'Control.Lens.Fold.Fold' to each side of a tuple.</span>
<a name="line-441"></a><span class='hs-comment'>--</span>
<a name="line-442"></a><span class='hs-comment'>-- >>> ("hello",["world","!!!"])^..beside id traverse</span>
<a name="line-443"></a><span class='hs-comment'>-- ["hello","world","!!!"]</span>
<a name="line-444"></a><span class='hs-definition'>beside</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Applicative</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s'</span> <span class='hs-varid'>t'</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>LensLike</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span><span class='hs-varid'>s'</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>t</span><span class='hs-layout'>,</span><span class='hs-varid'>t'</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
<a name="line-445"></a><span class='hs-definition'>beside</span> <span class='hs-varid'>l</span> <span class='hs-varid'>r</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>~</span><span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span><span class='hs-varid'>s'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>(,)</span> <span class='hs-varop'><$></span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varop'><*></span> <span class='hs-varid'>r</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s'</span>
<a name="line-446"></a><span class='hs-comment'>{-# INLINE beside #-}</span>
<a name="line-447"></a>
<a name="line-448"></a><span class='hs-comment'>-- | A traversal for tweaking the left-hand value of an 'Either':</span>
<a name="line-449"></a><span class='hs-comment'>--</span>
<a name="line-450"></a><span class='hs-comment'>-- >>> over _left (+1) (Left 2)</span>
<a name="line-451"></a><span class='hs-comment'>-- Left 3</span>
<a name="line-452"></a><span class='hs-comment'>-- >>> over _left (+1) (Right 2)</span>
<a name="line-453"></a><span class='hs-comment'>-- Right 2</span>
<a name="line-454"></a><span class='hs-comment'>-- >>> Right 42 ^._left :: String</span>
<a name="line-455"></a><span class='hs-comment'>-- ""</span>
<a name="line-456"></a><span class='hs-comment'>-- >>> Left "hello" ^._left</span>
<a name="line-457"></a><span class='hs-comment'>-- "hello"</span>
<a name="line-458"></a><span class='hs-comment'>--</span>
<a name="line-459"></a><span class='hs-comment'>-- @_left :: 'Applicative' f => (a -> f b) -> 'Either' a c -> f ('Either' b c)@</span>
<a name="line-460"></a><span class='hs-sel'>_left</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Traversal</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-varid'>a</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-varid'>b</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
<a name="line-461"></a><span class='hs-sel'>_left</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-conid'>Left</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Left</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span>
<a name="line-462"></a><span class='hs-sel'>_left</span> <span class='hs-keyword'>_</span> <span class='hs-layout'>(</span><span class='hs-conid'>Right</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>pure</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Right</span> <span class='hs-varid'>c</span>
<a name="line-463"></a><span class='hs-comment'>{-# INLINE _left #-}</span>
<a name="line-464"></a>
<a name="line-465"></a><span class='hs-comment'>-- | traverse the right-hand value of an 'Either':</span>
<a name="line-466"></a><span class='hs-comment'>--</span>
<a name="line-467"></a><span class='hs-comment'>-- @'_right' ≡ 'Data.Traversable.traverse'@</span>
<a name="line-468"></a><span class='hs-comment'>--</span>
<a name="line-469"></a><span class='hs-comment'>-- Unfortunately the instance for</span>
<a name="line-470"></a><span class='hs-comment'>-- @'Data.Traversable.Traversable' ('Either' c)@ is still missing from base,</span>
<a name="line-471"></a><span class='hs-comment'>-- so this can't just be 'Data.Traversable.traverse'</span>
<a name="line-472"></a><span class='hs-comment'>--</span>
<a name="line-473"></a><span class='hs-comment'>-- >>> over _right (+1) (Left 2)</span>
<a name="line-474"></a><span class='hs-comment'>-- Left 2</span>
<a name="line-475"></a><span class='hs-comment'>-- >>> over _right (+1) (Right 2)</span>
<a name="line-476"></a><span class='hs-comment'>-- Right 3</span>
<a name="line-477"></a><span class='hs-comment'>-- >>> Right "hello" ^._right</span>
<a name="line-478"></a><span class='hs-comment'>-- "hello"</span>
<a name="line-479"></a><span class='hs-comment'>-- >>> Left "hello" ^._right :: [Double]</span>
<a name="line-480"></a><span class='hs-comment'>-- []</span>
<a name="line-481"></a><span class='hs-comment'>--</span>
<a name="line-482"></a><span class='hs-comment'>-- @_right :: 'Applicative' f => (a -> f b) -> 'Either' c a -> f ('Either' c a)@</span>
<a name="line-483"></a><span class='hs-sel'>_right</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Traversal</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-varid'>c</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-varid'>c</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
<a name="line-484"></a><span class='hs-sel'>_right</span> <span class='hs-keyword'>_</span> <span class='hs-layout'>(</span><span class='hs-conid'>Left</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>pure</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Left</span> <span class='hs-varid'>c</span>
<a name="line-485"></a><span class='hs-sel'>_right</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-conid'>Right</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Right</span> <span class='hs-varop'><$></span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span>
<a name="line-486"></a><span class='hs-comment'>{-# INLINE _right #-}</span>
<a name="line-487"></a>
<a name="line-488"></a><a name="taking"></a><span class='hs-comment'>-- | Visit the first /n/ targets of a 'Traversal', 'Fold', 'Getter' or 'Lens'.</span>
<a name="line-489"></a><span class='hs-comment'>--</span>
<a name="line-490"></a><span class='hs-comment'>-- >>> [("hello","world"),("!!!","!!!")]^.. taking 2 (traverse.both)</span>
<a name="line-491"></a><span class='hs-comment'>-- ["hello","world"]</span>
<a name="line-492"></a><span class='hs-comment'>--</span>
<a name="line-493"></a><span class='hs-comment'>-- >>> [1..]^.. taking 3 traverse</span>
<a name="line-494"></a><span class='hs-comment'>-- [1,2,3]</span>
<a name="line-495"></a><span class='hs-comment'>--</span>
<a name="line-496"></a><span class='hs-comment'>-- >>> over (taking 5 traverse) succ "hello world"</span>
<a name="line-497"></a><span class='hs-comment'>-- "ifmmp world"</span>
<a name="line-498"></a><span class='hs-definition'>taking</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Applicative</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SimpleLensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>BazaarT</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SimpleLensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span>
<a name="line-499"></a><span class='hs-definition'>taking</span> <span class='hs-varid'>n</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>outsT</span> <span class='hs-varid'>b</span> <span class='hs-varop'><$></span> <span class='hs-varid'>traverse</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>take</span> <span class='hs-varid'>n</span> <span class='hs-varop'>$</span> <span class='hs-varid'>insT</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sellT</span> <span class='hs-varid'>s</span>
<a name="line-500"></a><span class='hs-comment'>{-# INLINE taking #-}</span>
<a name="line-501"></a>
<a name="line-502"></a><a name="dropping"></a><span class='hs-comment'>-- | Visit all but the first /n/ targets of a 'Traversal', 'Fold', 'Getter' or 'Lens'.</span>
<a name="line-503"></a><span class='hs-comment'>--</span>
<a name="line-504"></a><span class='hs-comment'>-- >>> ("hello","world") ^? dropping 1 both</span>
<a name="line-505"></a><span class='hs-comment'>-- Just "world"</span>
<a name="line-506"></a><span class='hs-comment'>--</span>
<a name="line-507"></a><span class='hs-comment'>-- Dropping works on infinite traversals as well.</span>
<a name="line-508"></a><span class='hs-comment'>--</span>
<a name="line-509"></a><span class='hs-comment'>-- >>> [1..]^? dropping 1 folded</span>
<a name="line-510"></a><span class='hs-comment'>-- Just 2</span>
<a name="line-511"></a><span class='hs-definition'>dropping</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Applicative</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SimpleLensLike</span> <span class='hs-layout'>(</span><span class='hs-conid'>Indexing</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SimpleLensLike</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span>
<a name="line-512"></a><span class='hs-definition'>dropping</span> <span class='hs-varid'>n</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>runIndexing</span> <span class='hs-layout'>(</span><span class='hs-varid'>l</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Indexing</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>i</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyword'>if</span> <span class='hs-varid'>i</span> <span class='hs-varop'>>=</span> <span class='hs-varid'>n</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>pure</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>i</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-num'>0</span> <span class='hs-keyword'>of</span>
<a name="line-513"></a> <span class='hs-layout'>(</span><span class='hs-varid'>r</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>r</span>
<a name="line-514"></a><span class='hs-comment'>{-# INLINE dropping #-}</span>
<a name="line-515"></a>
<a name="line-516"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-517"></a><span class='hs-comment'>-- Cloning Traversals</span>
<a name="line-518"></a><span class='hs-comment'>------------------------------------------------------------------------------</span>
<a name="line-519"></a>
<a name="line-520"></a><a name="cloneTraversal"></a><span class='hs-comment'>-- | A 'Traversal' is completely characterized by its behavior on a 'Bazaar'.</span>
<a name="line-521"></a><span class='hs-comment'>--</span>
<a name="line-522"></a><span class='hs-comment'>-- Cloning a 'Traversal' is one way to make sure you aren't given</span>
<a name="line-523"></a><span class='hs-comment'>-- something weaker, such as a 'Control.Lens.Traversal.Fold' and can be</span>
<a name="line-524"></a><span class='hs-comment'>-- used as a way to pass around traversals that have to be monomorphic in @f@.</span>
<a name="line-525"></a><span class='hs-comment'>--</span>
<a name="line-526"></a><span class='hs-comment'>-- Note: This only accepts a proper 'Traversal' (or 'Lens'). To clone a 'Lens'</span>
<a name="line-527"></a><span class='hs-comment'>-- as such, use 'cloneLens'</span>
<a name="line-528"></a><span class='hs-comment'>--</span>
<a name="line-529"></a><span class='hs-comment'>-- Note: It is usually better to 'ReifyTraversal' and use 'reflectTraversal'</span>
<a name="line-530"></a><span class='hs-comment'>-- than to 'cloneTraversal'. The former can execute at full speed, while the</span>
<a name="line-531"></a><span class='hs-comment'>-- latter needs to round trip through the 'Bazaar'.</span>
<a name="line-532"></a><span class='hs-comment'>--</span>
<a name="line-533"></a><span class='hs-comment'>-- >>> let foo l a = (view (cloneTraversal l) a, set (cloneTraversal l) 10 a)</span>
<a name="line-534"></a><span class='hs-comment'>-- >>> foo both ("hello","world")</span>
<a name="line-535"></a><span class='hs-comment'>-- ("helloworld",(10,10))</span>
<a name="line-536"></a><span class='hs-comment'>--</span>
<a name="line-537"></a><span class='hs-comment'>-- @'cloneTraversal' :: 'LensLike' ('Bazaar' a b) s t a b -> 'Traversal' s t a b@</span>
<a name="line-538"></a><span class='hs-definition'>cloneTraversal</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Applicative</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bazaar</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>f</span> <span class='hs-varid'>t</span>
<a name="line-539"></a><span class='hs-definition'>cloneTraversal</span> <span class='hs-varid'>l</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>bazaar</span> <span class='hs-varid'>f</span> <span class='hs-varop'>.</span> <span class='hs-varid'>l</span> <span class='hs-varid'>sell</span>
<a name="line-540"></a><span class='hs-comment'>{-# INLINE cloneTraversal #-}</span>
<a name="line-541"></a>
<a name="line-542"></a><a name="ReifiedTraversal"></a><span class='hs-comment'>-- | A form of 'Traversal' that can be stored monomorphically in a container.</span>
<a name="line-543"></a><a name="ReifiedTraversal"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>ReifiedTraversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>ReifyTraversal</span> <span class='hs-layout'>{</span> <span class='hs-varid'>reflectTraversal</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Traversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-layout'>}</span>
<a name="line-544"></a>
<a name="line-545"></a><a name="SimpleReifiedTraversal"></a><span class='hs-comment'>-- | @type SimpleReifiedTraversal = 'Simple' 'ReifiedTraversal'@</span>
<a name="line-546"></a><a name="SimpleReifiedTraversal"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>SimpleReifiedTraversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>ReifiedTraversal</span> <span class='hs-varid'>s</span> <span class='hs-varid'>s</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span>
<a name="line-547"></a>
</pre></body>
</html>