-
Notifications
You must be signed in to change notification settings - Fork 2
/
fbz_psycho_4.dart
105 lines (88 loc) · 2.26 KB
/
fbz_psycho_4.dart
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
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/// Pipeline-oriented programming with callable objects
void main(List<String> args) {
for (var i = 0; i < 31; i++) {
final output = FizzBuzzInitiator()(i)()()()();
print(output);
}
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class FizzBuzzData {
const FizzBuzzData({
required this.number,
required this.output,
});
final String output;
final int number;
FizzBuzzData copyWith({required String output}) {
return FizzBuzzData(number: number, output: output);
}
}
class FizzBuzzInitiator {
const FizzBuzzInitiator();
FizzBuzzCheckable call(int number) {
final fzd = FizzBuzzData(number: number, output: '');
return FizzBuzzCheckable(data: fzd);
}
}
class FizzBuzzCheckable {
const FizzBuzzCheckable({required this.data});
final FizzBuzzData data;
FizzCheckable call() {
bool notCheck = false;
FizzBuzzData newData = data;
if (data.number % 15 == 0) {
notCheck = true;
newData = data.copyWith(output: 'FizzBuzz,');
}
return FizzCheckable(data: newData, isCheckedData: notCheck);
}
}
class FizzCheckable {
const FizzCheckable({required this.data, required this.isCheckedData});
final FizzBuzzData data;
final bool isCheckedData;
BuzzCheckable call() {
if (isCheckedData) {
return BuzzCheckable(
data: data,
isCheckedData: isCheckedData,
);
}
bool notCheck = false;
FizzBuzzData newData = data;
if (data.number % 3 == 0) {
notCheck = true;
newData = data.copyWith(output: 'Fizz,');
}
return BuzzCheckable(data: newData, isCheckedData: notCheck);
}
}
class BuzzCheckable {
const BuzzCheckable({
required this.data,
required this.isCheckedData,
});
final FizzBuzzData data;
final bool isCheckedData;
Mappable call() {
if (isCheckedData) {
return Mappable(data: data);
}
FizzBuzzData newData = data;
if (data.number % 5 == 0) {
newData = data.copyWith(output: 'Buzz,');
}
return Mappable(data: newData);
}
}
class Mappable {
const Mappable({required this.data});
final FizzBuzzData data;
String call() {
if (data.output.isEmpty) {
return '${data.number},';
}
return data.output;
}
}