Skip to content

Latest commit

 

History

History
80 lines (66 loc) · 1.44 KB

#3 함수형프로그래밍.md

File metadata and controls

80 lines (66 loc) · 1.44 KB

날짜 2022-08-07 09:27

주제: 다트를 함수형 프로그래밍으로 이해하자.

#함수형프로그래밍 #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 객체지향 프로그래밍]] %%