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

パッケージ詳細v6.2.0

oxidized

より安全なプログラミングを促進するための、Rust風の型であるOptionとResultの定義。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.1万
いいね数
52
Pub ポイント
145

パッケージをインストール

flutter pub add oxidized

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Oxidized は、Dart に Rust をインスパイアした Option および Result 型を提供し、より安全で表現力豊かなエラー処理を可能にします。オプション値(Option)と失敗する可能性のある操作(Result)をモデル化することで、null に関連するバグを回避し、エラーを明示的に扱うのを助けます。これらの型は関数型プログラミングパターンを促進し、コードの明確さと堅牢性を向上させます。このパッケージは軽量であり、すべての主要プラットフォームにおける既存の Dart プロジェクトにシームレスに統合できます。

用途

  • null値を安全に扱う
  • null チェックを明示的な Option の使用に置き換える
  • 成功/失敗状態を使用した関数の結果の管理
  • 耐障害性のあるエラー処理ロジックの記述
  • Dartで関数型プログラミングパターンを採用する

主な機能

  • Rust風の Option タイプ
  • Rust風のResult型
  • 明示的な処理によるnull安全性
  • 関数型プログラミングユーティリティ
  • クロスプラットフォーム互換性

適している対象

  • nullのより安全な代替手段を探している開発者
  • 関数型プログラミングスタイルを採用するチーム
  • 堅牢なエラー管理を必要とするプロジェクト
  • 複数のプラットフォームをターゲットにする Dart アプリケーション
  • null参照による実行時クラッシュを減らしたい人

注意事項

  • Option/Result に馴染みのない開発者の学習曲線
  • 単純なケースにおける潜在的な冗長性
  • 過剰設計を避けるために慎重な統合が必要です
  • Dart の組み込みの null 安全性の代替ではありません
  • 小さなまたは単純な関数における複雑さを増加させる可能性があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

oxidized

A Dart package with types similar to those found in Rust, such as the Result which represents either a value or an error, and Option which either contains Some value or None.

Motivation

The Option and Result types are akin to the "sum types" found in languages such as OCaml and Rust. They encourage safer code by making errors and possible "null" values (i.e. None) a necessary part of the code flow, requiring you to deal with these cases appropriately. For an illustration of how this style of coding can prove to be helpful, see the excellent tutorial series by Matt Rešetá Flutter TDD Clean Architecture Course – Entities & Use Cases in which he uses the Either type from the dartz package to represent either a success or a failure. The Result type in this package is specifically designed for this purpose, making it easy to remember which part is the "success" and which is the "failure" (imagine trying to remember "Is the right side the failure? Or was it the left?").

Usage

A simple example using synchronous I/O to avoid nested futures is shown below. For additional examples, see the Dart code in the example directory.

import 'dart:io';
import 'package:oxidized/oxidized.dart';

Result<String, Exception> readFileSync(String name) {
  return Result.of(() {
    return File(name).readAsStringSync();
  });
}

void main() {
  var result = readFileSync('README.md');

  result.match((text) {
    print('first 80 characters of file:\n');
    print(text.substring(0, 80));
  }, (err) => print(err));

  // or in a more functional way:
  final msg = result.when(
    ok: (text) => 'first 80 characters of file:\n$text.substring(0, 80)',
    err: (err) => err,
  );
  print(msg);
}

Prior Art

The dartz package offers many functional programming helpers, including the Either type, which is similar to Result, with the difference being that it represents any two types of values.

The either_option package has both Either and Option and supports all of the typical functional operations.

The result package offers a few basic operations and may be adequate for simple cases.

The rust_like_result offers a simple Result type similar to the one in Rust.

The simple_result package provides a similar Result type based on the type of the same name in Swift.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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