#함수형프로그래밍 #Dart #입문
map 사용해서 문자열 다루기
void main() {
Map<String, String> harryPotter = {
'Harry Potter': '해리 포터',
'Ron Weasley': '론 위즐리',
'Hermione Granger': '헤르미온느 그레인저'
};
final result = harryPotter.map(
(key, value) => MapEntry(
'Herry Potter Character $key',
'해리포터 캐릭터 $value',
)
);
print(result);
}
map 을 사용해서 클래스로 변환하기
void main() {
final List<Map<String, String>> people = [
{
'name': '지수',
'group': '블랙핑크',
},
{
'name': '로제',
'group': '블랙핑크',
},
{
'name': 'RM',
'group': 'BTS',
},
{
'name': '뷔',
'group': 'BTS',
}
];
print(people);
final parsedPeople = people.map((x) => Person(
name: x['name']!,
group: x['group']!,
)).toList();
print(parsedPeople);
}
class Person {
final String name;
final String group;
Person({
required this.name,
required this.group,
});
@override
String toString(){
return 'name is $name and group is $group';
}
}
%% - [[1. note/study/dart/#4 비동기프로그래밍]] %% %% - [[1. note/study/dart/#2 객체지향 프로그래밍]] %%