パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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 セーフティとの統合
  • ネストされたおよび再帰的なユニオンのサポート

適している対象

  • 関数型プログラミングパターンを使用する開発者
  • 堅牢な状態管理を必要とするFlutterアプリ
  • 型安全性と保守性を最優先とするチーム
  • 複雑な条件論理を備えたプロジェクト
  • 明確なエラーおよび結果処理を必要とするアプリケーション

注意事項

  • 和型およびパターンマッチングの理解が必要です
  • 新しいチームメンバーの初期学習曲線を増加させる可能性がある
  • 変種ロジックのない単純なデータ構造には適していません
  • Dart の静的解析制約に制限される
  • 最適なセキュリティを実現するために、Lintルールと併用することをお勧めします

元の 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

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト