패키지, 저장소 및 앱 카테고리 검색

패키지 상세v3.0.3+1

sealed_unions

Dart용 시드 유니언

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
44
좋아요
47
Pub 점수
120

패키지 설치

flutter pub add sealed_unions

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Sealed Unions for Dart는 Dart에서 합유형(또는 대수적 데이터 유형이라고도 함)을 타입 안전하게 모델링할 수 있도록 해주는 패키지입니다. 개발자가 특정 타입에 대한 가능한 경우의 수를 유한 집합으로 정의할 수 있게 하여 컴파일 시점에서 완전한 패턴 매칭을 보장합니다. 이는 런타임 오류를 방지하고 여러 다른 상태나 결과를 다룰 때 코드의 명확성을 향상시켜 줍니다. 이 패키지는 Flutter 및 Dart 애플리케이션 내에서 함수형 프로그래밍 패턴에 특히 유용합니다.

사용 사례

  • UI에서 상태 전이 처리
  • 다양한 성공/실패 변형을 가진 API 응답 모델링
  • 유한 상태 기계 구현
  • 타입화된 결과를 사용한 오류 처리 관리
  • 명확한 케이스 구분을 통해 도메인 모델 만들기

주요 기능

  • 유니온 케이스를 위한 컴파일 시 안전성
  • 포괄적인 패턴 매칭 지원
  • 시크릿 타입을 정의하는 깔끔한 문법
  • Dart의 null 안전성과의 통합
  • 중첩 및 재귀적 유니온 지원

적합한 대상

  • 함수형 프로그래밍 패턴을 사용하는 개발자
  • 강력한 상태 관리가 필요한 플러터 앱
  • 유형 안전성과 유지보수성을 우선시하는 팀
  • 복잡한 조건 논리를 가진 프로젝트
  • 명확한 오류 및 결과 처리가 필요한 응용 프로그램

고려 사항

  • 합 유형과 패턴 매칭에 대한 이해가 필요합니다
  • 새로운 팀원들의 초기 학습 곡선을 증가시킬 수 있음
  • 변형 로직이 없는 간단한 데이터 구조에는 적합하지 않습니다
  • Dart의 정적 분석 제약에 국한됨
  • 최적의 안전성을 위해 린터 규칙과 함께 사용하는 것이 가장 좋습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Flutter Community: sealed_unions

ACKNOWLEDGEMENTS

This library is a port of JavaSealedUnions originally created by Francisco (Paco) Estévez .

Dart port by George Medve with assistance from Jan Knotek and Brian Egan.

RATIONALE

Sealed classes are used for representing restricted class hierarchies, when a value can have one of the types from a limited set, but cannot have any other type. They are, in a sense, an extension of enum classes: the set of values for an enum type is also restricted, but each enum constant exists only as a single instance, whereas a subclass of a sealed class can have multiple instances which can contain state. Sealed classes are available in languages like Kotlin, or C#. Tagged unions are common on Swift and Rust.

We highly recommend reading the Rationale for the readme of JavaSealedUnions for an indepth explanation of the idea and application of the library.

MOTIVATION

This library was heavily inspired by RxEither and the wonderful Domain Driven Design (DDD) talk by Scott Wlaschin. This video by Scott Wlaschin will inspire you on how to apply DDD: Domain Driven Design, F# and Types

USAGE

The following example project: MVI Sealed Unions demonstrates the library application in a Flutter app.

INSTALLING

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  sealed_unions: "^3.0.3+1"
2.Install it

You can install packages from the command line:

with Flutter:

flutter packages get

with pub:

pub get
3. Import it

Now in your Dart code, you can use:

// for example import Union4
import 'package:sealed_unions/union_4.dart';

License

Copyright (c) fluttercommunity 2019

The Apache Software License, Version 2.0

See LICENSE.md

Flutter Community: sealed_unions

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트