Skip to content

Commit 596ddc2

Browse files
mejorar version
1 parent 957096a commit 596ddc2

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

lib/dynamic/fizzbuzz.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
String fizzbuzz(int n) {
2-
return switch(n) {
2+
return switch (n) {
33
int x when x % 3 == 0 && x % 5 == 0 => 'FizzBuzz',
44
int x when x % 3 == 0 => 'Fizz',
55
int x when x % 5 == 0 => 'Buzz',
6-
_ => '$n'
6+
_ => '$n'
77
};
88
}

lib/dynamic/pattern.dart

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,81 @@
1-
21
// root element
32
abstract class Element {
43
String get();
54
}
65

7-
86
// html element
9-
abstract class HtmlElement extends Element {
10-
11-
}
7+
abstract class HtmlElement extends Element {}
128

139
final class Div extends HtmlElement {
10+
@override
1411
String get() {
15-
return "";
12+
return '';
1613
}
1714
}
1815

1916
final class Span extends HtmlElement {
17+
@override
2018
String get() {
21-
return "";
19+
return '';
2220
}
2321
}
2422

2523
final class Paragraph extends HtmlElement {
24+
@override
2625
String get() {
27-
return "";
26+
return '';
2827
}
2928
}
3029

3130
final class Image extends HtmlElement {
31+
@override
3232
String get() {
33-
return "";
33+
return '';
3434
}
3535
}
3636

37-
3837
// internal element
39-
abstract class InternalElement extends Element {
40-
41-
}
38+
abstract class InternalElement extends Element {}
4239

4340
final class Text extends InternalElement {
41+
@override
4442
String get() {
45-
return "";
43+
return '';
4644
}
4745
}
4846

4947
final class HtmlLiteral extends InternalElement {
48+
@override
5049
String get() {
51-
return "";
50+
return '';
5251
}
5352
}
5453

5554
final class Nothing extends InternalElement {
55+
@override
5656
String get() {
57-
return "";
57+
return '';
5858
}
5959
}
6060

61-
6261
// custom element
63-
abstract class CustomElement extends Element {
64-
65-
}
66-
67-
62+
abstract class CustomElement extends Element {}
6863

6964
String getElement(Element element) {
7065
return switch (element) {
7166
HtmlElement html => switch (html) {
72-
Div div => '<div>' + div.get() + '</div>',
73-
Span span => '<span>' + span.get() + '</span>',
74-
Paragraph paragraph => '<p>' + paragraph.get() + '</p>',
75-
Image image => '<img src="' + image.get() + '" />',
76-
_ => throw UnimplementedError(),
77-
},
67+
Div div => '<div>' + div.get() + '</div>',
68+
Span span => '<span>' + span.get() + '</span>',
69+
Paragraph paragraph => '<p>' + paragraph.get() + '</p>',
70+
Image image => '<img src="' + image.get() + '" />',
71+
_ => throw UnimplementedError(),
72+
},
7873
InternalElement internal => switch (internal) {
79-
Text text => text.get(),
80-
HtmlLiteral htmlLiteral => htmlLiteral.get(),
81-
Nothing nothing => nothing.get(),
82-
_ => throw UnimplementedError(),
83-
},
74+
Text text => text.get(),
75+
HtmlLiteral htmlLiteral => htmlLiteral.get(),
76+
Nothing nothing => nothing.get(),
77+
_ => throw UnimplementedError(),
78+
},
8479
CustomElement custom => custom.toString(),
8580
_ => throw UnimplementedError(),
8681
};

test/dynamic/pattern_test.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ void main() {
88

99
print('-- Pattern -- \n\n');
1010

11-
if (element is Div) {
12-
print('div');
13-
}
14-
15-
if (element is HtmlElement) {
16-
print('html element');
17-
}
18-
19-
if (element is Element) {
20-
print('element');
21-
}
11+
// if (element is Div) {
12+
// print('div');
13+
// }
14+
//
15+
// if (element is HtmlElement) {
16+
// print('html element');
17+
// }
18+
//
19+
// if (element is Element) {
20+
// print('element');
21+
// }
2222

2323
print(getElement(element) + '\n\n');
2424

0 commit comments

Comments
 (0)