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