-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1588 lines (1329 loc) · 70 KB
/
index.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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"><title>Unveiling the Magic</title><link rel="stylesheet" href="./reveal.js/dist/reset.css"><link rel="stylesheet" href="./reveal.js/dist/reveal.css"><link rel="stylesheet" href="./reveal.js/dist/theme/black.css" id="theme"><!--This CSS is generated by the Asciidoctor reveal.js converter to further integrate AsciiDoc's existing semantic with reveal.js--><style type="text/css">.reveal div.right {
float: right
}
/* source blocks */
.reveal .listingblock.stretch > .content {
height: 100%
}
.reveal .listingblock.stretch > .content > pre {
height: 100%
}
.reveal .listingblock.stretch > .content > pre > code {
height: 100%;
max-height: 100%
}
/* auto-animate feature */
/* hide the scrollbar when auto-animating source blocks */
.reveal pre[data-auto-animate-target] {
overflow: hidden;
}
.reveal pre[data-auto-animate-target] code {
overflow: hidden;
}
/* add a min width to avoid horizontal shift on line numbers */
code.hljs .hljs-ln-line.hljs-ln-n {
min-width: 1.25em;
}
/* tables */
table {
border-collapse: collapse;
border-spacing: 0
}
table {
margin-bottom: 1.25em;
border: solid 1px #dedede
}
table thead tr th, table thead tr td, table tfoot tr th, table tfoot tr td {
padding: .5em .625em .625em;
font-size: inherit;
text-align: left
}
table tr th, table tr td {
padding: .5625em .625em;
font-size: inherit
}
table thead tr th, table tfoot tr th, table tbody tr td, table tr td, table tfoot tr td {
display: table-cell;
line-height: 1.6
}
td.tableblock > .content {
margin-bottom: 1.25em
}
td.tableblock > .content > :last-child {
margin-bottom: -1.25em
}
table.tableblock, th.tableblock, td.tableblock {
border: 0 solid #dedede
}
table.grid-all > thead > tr > .tableblock, table.grid-all > tbody > tr > .tableblock {
border-width: 0 1px 1px 0
}
table.grid-all > tfoot > tr > .tableblock {
border-width: 1px 1px 0 0
}
table.grid-cols > * > tr > .tableblock {
border-width: 0 1px 0 0
}
table.grid-rows > thead > tr > .tableblock, table.grid-rows > tbody > tr > .tableblock {
border-width: 0 0 1px
}
table.grid-rows > tfoot > tr > .tableblock {
border-width: 1px 0 0
}
table.grid-all > * > tr > .tableblock:last-child, table.grid-cols > * > tr > .tableblock:last-child {
border-right-width: 0
}
table.grid-all > tbody > tr:last-child > .tableblock, table.grid-all > thead:last-child > tr > .tableblock, table.grid-rows > tbody > tr:last-child > .tableblock, table.grid-rows > thead:last-child > tr > .tableblock {
border-bottom-width: 0
}
table.frame-all {
border-width: 1px
}
table.frame-sides {
border-width: 0 1px
}
table.frame-topbot, table.frame-ends {
border-width: 1px 0
}
.reveal table th.halign-left, .reveal table td.halign-left {
text-align: left
}
.reveal table th.halign-right, .reveal table td.halign-right {
text-align: right
}
.reveal table th.halign-center, .reveal table td.halign-center {
text-align: center
}
.reveal table th.valign-top, .reveal table td.valign-top {
vertical-align: top
}
.reveal table th.valign-bottom, .reveal table td.valign-bottom {
vertical-align: bottom
}
.reveal table th.valign-middle, .reveal table td.valign-middle {
vertical-align: middle
}
table thead th, table tfoot th {
font-weight: bold
}
tbody tr th {
display: table-cell;
line-height: 1.6
}
tbody tr th, tbody tr th p, tfoot tr th, tfoot tr th p {
font-weight: bold
}
thead {
display: table-header-group
}
.reveal table.grid-none th, .reveal table.grid-none td {
border-bottom: 0 !important
}
/* kbd macro */
kbd {
font-family: "Droid Sans Mono", "DejaVu Sans Mono", monospace;
display: inline-block;
color: rgba(0, 0, 0, .8);
font-size: .65em;
line-height: 1.45;
background: #f7f7f7;
border: 1px solid #ccc;
-webkit-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 0 0 .1em white inset;
box-shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 0 0 .1em #fff inset;
margin: 0 .15em;
padding: .2em .5em;
vertical-align: middle;
position: relative;
top: -.1em;
white-space: nowrap
}
.keyseq kbd:first-child {
margin-left: 0
}
.keyseq kbd:last-child {
margin-right: 0
}
/* callouts */
.conum[data-value] {
display: inline-block;
color: #fff !important;
background: rgba(0, 0, 0, .8);
-webkit-border-radius: 50%;
border-radius: 50%;
text-align: center;
font-size: .75em;
width: 1.67em;
height: 1.67em;
line-height: 1.67em;
font-family: "Open Sans", "DejaVu Sans", sans-serif;
font-style: normal;
font-weight: bold
}
.conum[data-value] * {
color: #fff !important
}
.conum[data-value] + b {
display: none
}
.conum[data-value]:after {
content: attr(data-value)
}
pre .conum[data-value] {
position: relative;
top: -.125em
}
b.conum * {
color: inherit !important
}
.conum:not([data-value]):empty {
display: none
}
/* Callout list */
.hdlist > table, .colist > table {
border: 0;
background: none
}
.hdlist > table > tbody > tr, .colist > table > tbody > tr {
background: none
}
td.hdlist1, td.hdlist2 {
vertical-align: top;
padding: 0 .625em
}
td.hdlist1 {
font-weight: bold;
padding-bottom: 1.25em
}
/* Disabled from Asciidoctor CSS because it caused callout list to go under the
* source listing when .stretch is applied (see #335)
* .literalblock+.colist,.listingblock+.colist{margin-top:-.5em} */
.colist td:not([class]):first-child {
padding: .4em .75em 0;
line-height: 1;
vertical-align: top
}
.colist td:not([class]):first-child img {
max-width: none
}
.colist td:not([class]):last-child {
padding: .25em 0
}
/* Override Asciidoctor CSS that causes issues with reveal.js features */
.reveal .hljs table {
border: 0
}
/* Callout list rows would have a bottom border with some reveal.js themes (see #335) */
.reveal .colist > table th, .reveal .colist > table td {
border-bottom: 0
}
/* Fixes line height with Highlight.js source listing when linenums enabled (see #331) */
.reveal .hljs table thead tr th, .reveal .hljs table tfoot tr th, .reveal .hljs table tbody tr td, .reveal .hljs table tr td, .reveal .hljs table tfoot tr td {
line-height: inherit
}
/* Columns layout */
.columns .slide-content {
display: flex;
}
.columns.wrap .slide-content {
flex-wrap: wrap;
}
.columns.is-vcentered .slide-content {
align-items: center;
}
.columns .slide-content > .column {
display: block;
flex-basis: 0;
flex-grow: 1;
flex-shrink: 1;
}
.columns .slide-content > .column > * {
padding: .75rem;
}
/* See #353 */
.columns.wrap .slide-content > .column {
flex-basis: auto;
}
.columns .slide-content > .column.is-full {
flex: none;
width: 100%;
}
.columns .slide-content > .column.is-four-fifths {
flex: none;
width: 80%;
}
.columns .slide-content > .column.is-three-quarters {
flex: none;
width: 75%;
}
.columns .slide-content > .column.is-two-thirds {
flex: none;
width: 66.6666%;
}
.columns .slide-content > .column.is-three-fifths {
flex: none;
width: 60%;
}
.columns .slide-content > .column.is-half {
flex: none;
width: 50%;
}
.columns .slide-content > .column.is-two-fifths {
flex: none;
width: 40%;
}
.columns .slide-content > .column.is-one-third {
flex: none;
width: 33.3333%;
}
.columns .slide-content > .column.is-one-quarter {
flex: none;
width: 25%;
}
.columns .slide-content > .column.is-one-fifth {
flex: none;
width: 20%;
}
.columns .slide-content > .column.has-text-left {
text-align: left;
}
.columns .slide-content > .column.has-text-justified {
text-align: justify;
}
.columns .slide-content > .column.has-text-right {
text-align: right;
}
.columns .slide-content > .column.has-text-left {
text-align: left;
}
.columns .slide-content > .column.has-text-justified {
text-align: justify;
}
.columns .slide-content > .column.has-text-right {
text-align: right;
}
.text-left {
text-align: left !important
}
.text-right {
text-align: right !important
}
.text-center {
text-align: center !important
}
.text-justify {
text-align: justify !important
}
.footnotes {
border-top: 1px solid rgba(0, 0, 0, 0.2);
padding: 0.5em 0 0 0;
font-size: 0.65em;
margin-top: 4em;
}
.byline {
font-size:.8em
}
ul.byline {
list-style-type: none;
}
ul.byline li + li {
margin-top: 0.25em;
}
</style><script>window.MathJax = {"tex":{"inlineMath":[["\\(", "\\)"]], "displayMath":[["\\[", "\\]"]], "processEscapes":false, "tags":"none"}, "options":{"ignoreHtmlClass":"nostem|nolatexmath"}, "asciimath":{"delimiters":[["\\$", "\\$"]]}, "loader":{"load":["input/asciimath", "output/chtml", "ui/menu"]}};</script><script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.js"></script></head><body><div class="reveal"><div class="slides"><section class="title" data-state="title"><h1>Unveiling the Magic</h1><div class="preamble"><div class="paragraph"><p><strong>Chimney’s Internals, Macros & Scala 3 Transition</strong></p></div>
<div class="paragraph"><p>Mateusz Kubuszok</p></div></div></section>
<section id="_about_me"><h2>About me</h2><div class="slide-content"><div class="ulist"><ul><li class="fragment"><p>breaking things in Scala for 8+ years</p></li><li class="fragment"><p>breaking things for money for 10 years</p></li><li class="fragment"><p>breaking things for fun for 18(?) years</p></li><li class="fragment"><p>a little bit of open source - including co-authoring Chimney for 6 years now</p></li><li class="fragment"><p>blog at <a href="https://kubuszok.com">Kubuszok.com</a></p></li><li class="fragment"><p>niche <a href="https://leanpub.com/jvm-scala-book">Things you need to know about JVM (that matter in Scala)</a> ebook</p></li></ul></div>
<aside class="notes"><div class="paragraph"><p>Every presentation should start with some excuse, why you even are here</p></div></aside></div></section>
<section id="_agenda"><h2>Agenda</h2><div class="slide-content"><div class="ulist"><ul><li class="fragment"><p>what are Chimney’s features</p></li><li class="fragment"><p>what kind of code are we generating</p></li><li class="fragment"><p>goals for the migration to Scala 2+3</p></li><li class="fragment"><p>research and the current state</p></li></ul></div>
<aside class="notes"><div class="paragraph"><p>I’ll skip explaining why Chimney exists because previous presentation already dscussed the use cases.</p></div>
<div class="paragraph"><p>I’ll list features because it will help understand what we are generating and what we are supporting.</p></div></aside></div></section>
<section><section id="_chimneys_features"><h2>Chimney’s features</h2></section><section id="_case_class_conversions"><h2><code>case class</code> conversions</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">import io.scalaland.chimney.dsl.* // assume this from now on</code></pre></div></div>
<div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
case class Bar(a: Int, b: Double) // same fields
Foo(1, 2.0).transformInto[Bar] // Bar(1, 2.0)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>If every field in <code>Bar</code> has a corresponding field in <code>Foo</code> and fields don’t have to be converted, transformation doesn’t require any configuration.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
case class Bar(a: Int, c: Double) // c instead of b
Foo(1, 2.0).into[Bar]
.withFieldRenamed(_.b, _.c)
.transform // Bar(1, 2.0)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>If we don’t want to provide value because field can take value from another field we can use rename.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
case class Bar(a: Int, b: Double, c: String) // extra field
Foo(1, 2.0).into[Bar]
.withFieldConst(_.c, "test")
.transform // Bar(1, 2.0, "test")</code></pre></div></div>
<div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
case class Bar(a: Int, b: Double, c: String) // extra field
Foo(1, 2.0).into[Bar]
.withFieldComputed(_.c, foo => foo.toString)
.transform // Bar(1, 2.0, "Foo(1, 2.0)")</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>If we have to fill an new field, we can use provide constant or compute the value.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
case class Bar(a: Int, b: Double, c: String = "c") // ditto
Foo(1, 2.0).into[Bar]
.enableDefaultValues
.transform // Bar(1, 2.0, "c")</code></pre></div></div>
<div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
case class Bar(a: Int, b: Double, c: Option[String])//ditto
Foo(1, 2.0).into[Bar]
.enableOptionDefaultsToNone
.transform // Bar(1, 2.0, None)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Or we can use some defaults if no other way is available but some default is accessible.</p></div></aside></div></section><section id="_tuples_conversions"><h2>Tuples conversions</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
Foo(1, 2.0).transformInto[(Int, Double)] // (1, 2.0, None)
(1, 2.0).transformInto[Foo] // Foo(1, 2.0, None)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>If either side of a transformation is a tuple we match fields by their positions instead of names.</p></div></aside></div></section><section id="_java_beans_conversions"><h2>Java Beans conversions</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: Double)
class Bar private (
@BeanProperty var a: Int,
@BeanProperty var b: Double
) {
def this() = this(0, 0.0)
}
Foo(1, 2.0).into[Bar].enableBeanSetters.transform
import scala.util.chaining.*
new Bar().pipe(_.setA(1)).pipe(_.setB(2.0))
.into[Foo].enableBeanGetters.transform</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Instead of a case class we might use a Java Bean as well.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">class Foo {
def a: Int = 1
}
case class Bar(a: Int)
Foo(1).into[Bar].enableMethodAccessors.transform</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>By default only <code>case class</code> fields are takein into consideration.</p></div></aside></div></section><section id="_sealed_hierarches_conversions"><h2><code>sealed</code> hierarches conversions</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">sealed trait Foo
object Foo {
case object A extends Foo
case class B(b: Int) extends Foo
}
sealed trait Bar // same subtypes
object Bar {
case object A extends Foo
case class B(b: Int) extends Bar
}
(Foo.A : Foo).transformInto[Bar] // Bar.A
(Foo.B(1) : Foo).transformInto[Bar] // Bar.B(1)</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">sealed trait Foo
object Foo {
case object A extends Foo
case class B(b: Int) extends Foo
case class C(c: Double) extends Foo
}
sealed trait Bar // missing Bar.C
object Bar {
case object A extends Foo
case class B(b: Int) extends Bar
}
(Foo.C(2.0) : Foo).into[Bar].withCoproductInstance[Foo.C] {
case Foo.C(c) => Bar.B(c.toInt)
}.transform // Bar.B(2)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>There is an interesting duality between products and coproducts: products require that all output fields have sources, and coproducts require that all input types have targets.</p></div></aside></div></section><section id="_anyval_conversions"><h2><code>AnyVal</code> conversions</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(val value: Int) extends AnyVal
case class Bar(val value: Int) extends AnyVal
Foo(1).transformInto[Bar] // Bar(1)
Foo(1).transformInto[Int] // 1
1.transformInto[Bar] // Bar(1)</code></pre></div></div></div></section><section id="_implicit_transformer"><h2>Implicit <code>Transformer</code></h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">class SomeType(val x: Int)
class AnotherType(val y: Int)
case class Foo(a: SomeType, b: Int)
case class Bar(a: AnotherType, b: Int)
foo.transformInto[Bar] // error: how to convert foo.a?</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">import io.scalaland.chimney.Transformer
implicit val someTypeToAnotherType:
Transformer[SomeType, AnotherType] =
st => new AnotherType(y = st.x) // single abstract method
foo.transformInto[Bar]//uses someTypeToAnotherType for foo.a</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>This shows the true power of Chimney as transformetions can be generated recursively and then we only have to manually plug-in the types which cannot be figured out.</p></div></aside></div></section><section id="_implicit_transformerconfiguration"><h2>Implicit <code>TransformerConfiguration</code></h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val cfg = TransformerConfiguration.default
.enableDefaultValues
.enableOptionDefaultsToNone
.enableBeanGetters
.enableBeanSetters
// now .into.transform and .transformInto use above flags</code></pre></div></div></div></section><section id="_partial_transformers"><h2>Partial Transformers</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Option[Int])
case class Bar(a: Int)
Foo(None).transformInto[Bar] // cannot handle None!</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val result = Foo(None).transformIntoPartial[Bar]
result.asEither // Left(...)
result.asErrorPathMessages
// Iterable("a" -> ErrorMessage.EmptyValue)</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val intToString:
Transformer[Int, String] =
int => int.toString
implicit val stringToInt:
PartialTransformer[String, Int] =
PartialTransformer { str =>
partial.Result.fromCatching(str.toInt)
}
case class Foo(a: Option[Int], b: String)
case class Bar(a: String, b: Int)
Foo(None, "test").transformIntoPartial[Bar]</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Partial has all the properties of toral transformers and more.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">// from is case class
from.intoPartial[To]
// total operations
.withFieldRenamed(_.a, _.b)
.withFieldConst(_.c, value)
.withFieldComputed(_.d, from => ...)
// partial operations
.withFieldComputedPartial(_.e, from => ...)
.transform</code></pre></div></div>
<div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">// from is sealed hierarchy
from.intoPartial[To]
// total operations
.withCoproductInstance[To.Subtype](...)
// partial operations
.withCoproductInstancePartial[To.Subtype](...)
.transform</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val totalInt2String:
Transformer[String, Int] =
str => scala.util.Try(str.toInt).getOrElse(0)
implicit val stringToInt:
PartialTransformer[String, Int] =
PartialTransformer { str =>
partial.Result.fromCatching(str.toInt)
}
case class Foo(a: String)
case class Bar(a: Int)
Foo(1).transformIntoPartial[Bar] // error: ambiguity!</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val cfg = TransformerConfiguration.default
.enableImplicitConflictResolution(PreferTotalTransformer)
/* or
.enableImplicitConflictResolution(PreferPartialTransformer)
*/</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val stringToInt:
PartialTransformer[String, Int] =
PartialTransformer.fromFunction(_.toInt)
case class Foo(a: String, foo: Foo2)
case class Foo2(b: String)
case class Bar(a: Int, foo: Bar2)
case class Bar2(b: Int)</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">Foo("a", Foo2("b"))
.transformIntoPartial[Bar]
.asErrorPathMessageStrings
// List("a" -> "For input string: \"a\"",
// "foo.b" -> "For input string: \"b"\")</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">Foo("a", Foo2("b"))
.transformIntoPartial[Bar](failFast = true)
.asErrorPathMessageStrings
// List("a" -> "For input string: \"a\"")</code></pre></div></div></div></section><section id="_patchers"><h2>Patchers</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: String, c: Double)
case class Patch(c: Double)
Foo(1, "2", 3.0).patchUsing(Patch(4.0)) // Foo(1, "2", 4.0)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Patchers are currently shallow, they don’t update things in-depth, and only support <code>case class</code>es.</p></div></aside></div></section></section>
<section><section id="_generated_code"><h2>Generated code</h2></section><section id="_are_we_generating_new_transformers"><h2>Are we generating <code>new Transformer</code>s?</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: String)
case class Bar(a: Int, b: String)
Foo(1, "b").transformInto[Bar]</code></pre></div></div>
<div class="paragraph"><p>Do we generate:</p></div>
<div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">new Transformer {
def transform(foo: Foo): Bar = Bar(
Transformer.identity[Int].transform(foo.a),
Transformer.identity[String].transform(foo.b)
)
}.transform(Foo(1, "b"))</code></pre></div></div>
<div class="paragraph"><p>?</p></div>
<aside class="notes"><div class="paragraph"><p>Answer: in the old times when it was a Shapeless project, we did, but for many years we don’t.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Int, b: String)
case class Bar(a: Int, b: String)
Foo(1, "b").transformInto[Bar]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo = Foo(1, "b")
new Bar(foo.a, foo.b)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Actually, what Chimney generates is the expression with the target type. Everything is inlined from the start.</p></div></aside></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val totalInt2String:
Transformer[String, Int] =
str => scala.util.Try(str.toInt).getOrElse(0)
case class Foo1(a: Int, b: String, foo: Foo2)
case class Foo2(f: String)
case class Bar1(a: Int, b: String, foo: Bar2)
case class Bar2(f: Int)
Foo1(1, "b", Foo2("9")).transformInto[Bar1]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo1 = Foo1(1, "b", Foo2("9"))
new Bar1(
foo1.a,
foo1.b,
new Bar2(totalInt2String.transform(foo1.foo.f))
)</code></pre></div></div></div></section><section id="_calling_unapply"><h2>Calling <code>unapply</code>?</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit val totalInt2String: Transformer[String, Int] = ...
sealed trait Foo3
object Foo3 {
case object A extends Foo3
case class B(b: String) extends Foo3 }
sealed trait Bar3
object Bar3 {
case object A extends Bar3
case class B(b: Int) extends Bar3 }
(Foo3.B("9"): Foo3).transformInto[Bar3]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo1 = (Foo3.B("9"): Foo3)
foo3 match {
case (_: Foo3.A.type) => Bar3.A
case (b @ (_: Foo3.B)) =>
new Bar3.B(totalInt2String.transform(b.b))
}</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Here <code>foo1</code> is name generated by compiler to avoid clashes, I also added new lines and indentations and remobed full qualifies names, but that’s basically expr that was generated.</p></div></aside></div></section><section id="_what_happens_when_we_customize_transformer"><h2>What happens when we customize <code>Transformer</code>?</h2></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo4(a: Int)
case class Bar4(a: Int, b: String, c: Double)
Foo4(1).into[Bar4]
.withFieldConst(_.b, "test")
.withFieldComputed(_.c, _.a.toDouble)
.transform</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val ti$1 = Foo4(1).into[Bar4] // <- stores runtime data
.__refineTransformerDefinition(td =>
td.__addOverride("test".asInstanceOf[scala.Any])
.__refineConfig[FieldConst["b",Empty]]
)
.__refineTransformerDefinition(td =>
td.__addOverride((_.a.toDouble).asInstanceOf[scala.Any]
.__refineConfig[FieldComputed["c",FieldConst["b",Empty]]])
)</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">new Transformer[Foo4, Bar4] {
def transform(foo4$1: Foo4): Bar4 = new Bar4(
foo4$1.a,
ti$1.td.runtimeData(1).asInstanceOf[String],
ti$1.td.runtimeData(0).asInstanceOf[Foo4 => Double](foo4$1)
)
}.transform(ti$1.source)</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>Users don’t have to call <code>.transform</code> immediatelly, they can build it in steps so we need to store input, constants and functions in some runtime representation.</p></div></aside></div></section><section id="_what_when_we_need_recursion"><h2>What when we need recursion?</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class FooR(a: Int, b: Option[FooR])
case class BarR(a: Int, b: Option[BarR])
FooR(1, Some(FooR(2, None))).transformInto[BarR] // error!</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit def fooBarR: Transformer[FooR, BarR] =
fooR => fooR.transformInto[Bar] // also error!
FooR(1, Some(FooR(2, None))).transformInto[BarR]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">implicit def fooBarR: Transformer[FooR, BarR] =
Transformer.derive[FooR, BarR]
FooR(1, Some(FooR(2, None))).transformInto[BarR]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">new BarR(foor.a, foor.b.map(b => fooBarR.transform(b)))</code></pre></div></div>
<aside class="notes"><div class="paragraph"><p>We cannot do inline derivation bacause it cannot handle recursion, we also cannot do transformInto within implicit because it would call itself.</p></div></aside></div></section><section id="_partial_transformers_combinators"><h2>Partial Transformers combinators?</h2></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo5_0(a: Int, b: Int, c: Int)
case class Bar5(a: Int, b: Int, c: Int)
implicit val stringToInt: PartialTransformer[String, Int] =
PartialTransformer.fromFunction[String, Int](_.toInt)
Foo5_0(1, 2, 3).transformIntoPartial[Bar5]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo5_0 = Foo5_0(1, 2, 3)
partial.Result.Value(new Bar5(foo5_0.a, foo5_0.b, foo5_0.c))</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo5_1(a: String, b: Int, c: Int)
case class Bar5(a: Int, b: Int, c: Int)
implicit val stringToInt: PartialTransformer[String, Int] =
PartialTransformer.fromFunction[String, Int](_.toInt)
Foo5_1("1", 2, 3).transformIntoPartial[Bar5]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo5_1 = Foo5_1("1", 2, 3)
stringToInt.transform(foo5_1.a)
.prependErrorPath(partial.PathElement.Accessor("a"))
.map((a: Int) => new Bar5(a, foo5_1.b, foo5_1.c)</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo5_2(a: String, b: String, c: Int)
case class Bar5(a: Int, b: Int, c: Int)
implicit val stringToInt: PartialTransformer[String, Int] =
PartialTransformer.fromFunction[String, Int](_.toInt)
Foo5_2("1", "2", 3).transformIntoPartial[Bar5]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo5_2 = Foo5_2("1", "2", 3)
partial.Result.map2[Int, Int, Bar5](
stringToInt.transform(foo5_2.a)
.prependErrorPath(partial.PathElement.Accessor("a")),
stringToInt.transform(foo5_2.b)
.prependErrorPath(partial.PathElement.Accessor("b")),
{
case (a: Int), (b : Int) => new Bar5(a, b, foo5_2.c)
},
failfast
)</code></pre></div></div></div></section><section><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo5_3(a: String, b: String, c: String)
case class Bar5(a: Int, b: Int, c: Int)
implicit val stringToInt: PartialTransformer[String, Int] =
PartialTransformer.fromFunction[String, Int](_.toInt)
Foo5_3("1", "2", "3").transformIntoPartial[Bar5]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">val foo5_3 = Foo5_3("1", "2", "3")
final def rd_a: partial.Result[Int] =
stringToInt.transform(foo5_3.a)
.prependErrorPath(partial.PathElement.Accessor("a"))
final def rd_b: partial.Result[Int] =
stringToInt.transform(foo5_3.b)
.prependErrorPath(partial.PathElement.Accessor("b"))
final def rd_c: partial.Result[Int] =
stringToInt.transform(foo5_3.c)
.prependErrorPath(partial.PathElement.Accessor("c"))
if (failfast)
for {
rvff_a <- rd_a
rvff_b <- rd_b
rvff_b <- rd_c
} yield new Bar5(rvff_a, rvff_b, rvff_c)
else {
var allerrors: partial.Result.Errors = null;
final val rv_a = rd_a
allerrors = partial.Result.Errors
.__mergeResultNullable(allerrors, rv_a)
final val rv_b = rd_b
allerrors = partial.Result.Errors
.__mergeResultNullable(allerrors, rv_b)
final val rv_c = rd_c
allerrors = partial.Result.Errors
.__mergeResultNullable(allerrors, rv_c)
if (allerrors == null)
partial.Result.Value(
new Bar5(
rv_a.asInstanceOf[partial.Result.Value[Int]].value,
rv_b.asInstanceOf[partial.Result.Value[Int]].value,
rv_c.asInstanceOf[partial.Result.Value[Int]].value
)
)
else
allerrors
}</code></pre></div></div></div></section><section><div class="slide-content"><div class="imageblock"><img src="benchmarks.png" alt="benchmarks"></div></div></section></section>
<section><section id="_migrations_goals_chimney_0_8_0"><h2>Migration’s goals (Chimney 0.8.0)</h2><div class="slide-content"><div class="ulist"><ul><li class="fragment"><p>source compatibility</p></li><li class="fragment"><p>(excluding deprecated features which are removed)</p></li><li class="fragment"><p>sharing as much code generation logic between Scala 2 and Scala 3 as possible</p></li></ul></div></div></section><section id="_enableunsafeoption_deprecation"><h2><code>enableUnsafeOption</code> deprecation</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Option[Int])
case class Bar(b: Int)
// this won't compile
Foo(None).transformInto[Bar]
// this is deprecated
Foo(None).into[Bar].enableUnsafeOption.transform</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">Foo(None).intoPartial[Bar].asOption // Option[Bar]
// alternatively, on your own risk!
// implicit def unsafeOption[A, B](
// implicit t: Transform[A, B]
// ): Transformer[Option[A], B] = ...
// Foo(None).transformInto[Bar]</code></pre></div></div></div></section><section id="_transformerf_deprecation"><h2><code>TransformerF</code> deprecation</h2><div class="slide-content"><div class="listingblock"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">case class Foo(a: Option[Int])
case class Bar(b: Int)
// deprecated
Foo(None).transformIntoF[Option, Bar]
Foo(None).transformIntoF[Either[String, +*], Bar]</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">Foo(None).transformIntoPartial[Bar].asOption
Foo(None).transformIntoPartial[Bar].asEither</code></pre></div></div></div></section></section>
<section><section id="_research_for_scala_3_migration"><h2>Research for Scala 3 migration</h2></section><section id="_are_differences_in_macros_the_issue"><h2>Are differences in macros the issue?</h2><div class="slide-content"><div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">trait Common {
type Type[A]
type Expr[A]
// methods working with Type[A] and Expr[A]
}</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">class Scala2Macro(val c: blackbox.Context) extends Common {
final Type[A] = c.Type @@ A // tagged type
final Expr[A] = c.Expr[A]
// platform-specific methods implementations
}</code></pre></div></div>
<div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala">class Scala3Macro(using q: quoted.Quotes) extends Common {
final Type[A] = quoted.Type[A]
final Expr[A] = quoted.Expr[A]
// platform-specific methods implementations
}</code></pre></div></div></div></section><section id="_so_what_is_the_actual_issue"><h2>So what is the actual issue?</h2><div class="slide-content"><div class="listingblock fragment"><div class="content"><pre class="highlightjs highlight"><code class="language-scala hljs" data-noescape="true" data-lang="scala"> def mkTransformerBodyTree(
To: Type,
targets: Seq[Target],
bodyTreeArgs: Seq[DerivedTree],
derivationTarget: DerivationTarget
)(
mkTargetValueTree: Seq[Tree] => Tree
): DerivedTree = {
assert(targets.size == bodyTreeArgs.size, "targets arity must correspond to the argument trees arity")
derivationTarget match {
case DerivationTarget.TotalTransformer =>
assertOrAbort(
bodyTreeArgs.forall(_.isTotalTarget),
"All derived body trees arguments must be total in Total target derivation!"
)
DerivedTree.fromTotalTree(mkTargetValueTree(bodyTreeArgs.map(_.tree)))
case pt: DerivationTarget.PartialTransformer =>
assertOrAbort(
bodyTreeArgs.forall(a => a.isTotalTarget || a.isPartialTarget),
"Only Total and Partial body tree arguments are supported in Partial target derivation!"
)
val (totalArgs, partialArgs) = (targets zip bodyTreeArgs).partition(_._2.isTotalTarget)
if (partialArgs.isEmpty) {
DerivedTree.fromTotalTree(mkTargetValueTree(bodyTreeArgs.map(_.tree)))
} else if (partialArgs.sizeIs == 1) {
val (target, bodyTree) = partialArgs.head
val fn = freshTermName(target.name)
val totalArgsMap = totalArgs.map { case (target, bt) => target -> bt.tree }.toMap
val argsMap = totalArgsMap + (target -> q"$fn")
val updatedArgs = targets.map(argsMap)
DerivedTree(q"${bodyTree.tree}.map { ($fn: ${target.tpe}) => ${mkTargetValueTree(updatedArgs)} }", pt)
} else if (partialArgs.sizeIs == 2) {
val (target0, bodyTree0) = partialArgs.head
val (target1, bodyTree1) = partialArgs.last
val fn0 = freshTermName(target0.name)
val fn1 = freshTermName(target1.name)
val totalArgsMap = totalArgs.map { case (target, bt) => target -> bt.tree }.toMap
val argsMap = totalArgsMap + (target0 -> q"$fn0") + (target1 -> q"$fn1")
val updatedArgs = targets.map(argsMap)
val tree = Trees.PartialResult
.map2(
target0.tpe,
target1.tpe,
To,
bodyTree0.tree,
bodyTree1.tree,
q"{ case ($fn0: ${target0.tpe}, $fn1: ${target1.tpe}) => ${mkTargetValueTree(updatedArgs)} }",
pt.failFastTree
)
DerivedTree(tree, pt)
} else {
val totalArgsMap = totalArgs.map { case (target, bt) => target -> bt.tree }.toMap
val partialTargets = partialArgs.map(_._1)
val localDefNames = partialTargets.map(t => freshTermName(s"rd_${t.name}"))
val localTreeDefs = (localDefNames zip partialArgs).map { case (dn, (target, tbt)) =>
q"final def $dn: ${Trees.PartialResult.tpe(target.tpe)} = { ${tbt.tree} }"
}
val localValNames = partialTargets.map(t => freshTermName(s"rv_${t.name}"))
// short circuit branch (fail fast)
val succFFValIdents = partialTargets.map(t => freshTermName(s"rvff_${t.name}"))
val succFFFqs = (succFFValIdents zip localDefNames).map { case (rvff, rd) => fq"$rvff <- $rd" }
val succValFFTrees = succFFValIdents.map(rvff => q"$rvff")
val patRefArgsMapFF = (partialTargets zip succValFFTrees).toMap
val argsMapFF = totalArgsMap ++ patRefArgsMapFF
val updatedArgsFF = targets.map(argsMapFF)
// long circuit branch (errors accumulation)
val succValTrees = (localValNames zip partialTargets).map { case (rv, target) =>
q"$rv.asInstanceOf[${Trees.PartialResult.valueTpe(target.tpe)}].value"
}
val patRefArgsMap = (partialTargets zip succValTrees).toMap
val argsMap = totalArgsMap ++ patRefArgsMap
val updatedArgs = targets.map(argsMap)
val allErrorsIdent = freshTermName("allErrors")
val errorsCaptureTrees = (localValNames zip localDefNames).flatMap { case (rv, rd) =>
Seq(
q"final val $rv = $rd",
q"""$allErrorsIdent = ${Trees.PartialErrors.mergeResultNullable(q"$allErrorsIdent", q"$rv")}"""
)
}
val tree = q"""{
..$localTreeDefs
if(${pt.failFastTree}) {
for (..$succFFFqs) yield ${mkTargetValueTree(updatedArgsFF)}
} else {
var $allErrorsIdent: ${Trees.PartialErrors.tpe} = null
..$errorsCaptureTrees
if ($allErrorsIdent == null) {
${Trees.PartialResult.value(mkTargetValueTree(updatedArgs))}
} else {
$allErrorsIdent
}
}
}"""
DerivedTree(tree, pt)
}
}
}</code></pre></div></div></div></section></section>
<section id="_questions"><h2>Questions?</h2></section>
<section id="_thank_you"><h2>Thank You!</h2></section></div></div><script src="./reveal.js/dist/reveal.js"></script><script>Array.prototype.slice.call(document.querySelectorAll('.slides section')).forEach(function(slide) {
if (slide.getAttribute('data-background-color')) return;
// user needs to explicitly say he wants CSS color to override otherwise we might break custom css or theme (#226)
if (!(slide.classList.contains('canvas') || slide.classList.contains('background'))) return;
var bgColor = getComputedStyle(slide).backgroundColor;
if (bgColor !== 'rgba(0, 0, 0, 0)' && bgColor !== 'transparent') {
slide.setAttribute('data-background-color', bgColor);
slide.style.backgroundColor = 'transparent';
}
});
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
// Display presentation control arrows
controls: true,
// Help the user learn the controls by providing hints, for example by
// bouncing the down arrow when they first encounter a vertical slide
controlsTutorial: true,
// Determines where controls appear, "edges" or "bottom-right"
controlsLayout: 'bottom-right',
// Visibility rule for backwards navigation arrows; "faded", "hidden"
// or "visible"
controlsBackArrows: 'faded',
// Display a presentation progress bar
progress: true,
// Display the page number of the current slide
slideNumber: false,
// Control which views the slide number displays on
showSlideNumber: 'all',
// Add the current slide number to the URL hash so that reloading the
// page/copying the URL will return you to the same slide
hash: false,
// Push each slide change to the browser history. Implies `hash: true`
history: true,
// Enable keyboard shortcuts for navigation
keyboard: true,
// Enable the slide overview mode
overview: true,
// Disables the default reveal.js slide layout so that you can use custom CSS layout
disableLayout: false,
// Vertical centering of slides
center: true,
// Enables touch navigation on devices with touch input
touch: true,
// Loop the presentation
loop: false,
// Change the presentation direction to be RTL
rtl: false,
// See https://github.com/hakimel/reveal.js/#navigation-mode
navigationMode: 'default',
// Randomizes the order of slides each time the presentation loads
shuffle: false,
// Turns fragments on and off globally
fragments: true,
// Flags whether to include the current fragment in the URL,
// so that reloading brings you to the same fragment position
fragmentInURL: true,
// Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen
embedded: false,
// Flags if we should show a help overlay when the questionmark
// key is pressed
help: true,
// Flags if speaker notes should be visible to all viewers
showNotes: false,
// Global override for autolaying embedded media (video/audio/iframe)
// - null: Media will only autoplay if data-autoplay is present
// - true: All media will autoplay, regardless of individual setting
// - false: No media will autoplay, regardless of individual setting
autoPlayMedia: null,
// Global override for preloading lazy-loaded iframes
// - null: Iframes with data-src AND data-preload will be loaded when within
// the viewDistance, iframes with only data-src will be loaded when visible
// - true: All iframes with data-src will be loaded when within the viewDistance