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

패키지 상세v6.2.0

oxidized

더 안전한 프로그래밍을 촉진하기 위한 러스트 스타일의 타입인 Option과 Result의 정의.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.1만
좋아요
52
Pub 점수
145

패키지 설치

flutter pub add oxidized

패키지 개요

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

Oxidized는 Dart에 루스트를 영감으로 한 Option 및 Result 타입을 제공하여 더 안전하고 표현력 있는 오류 처리를 가능하게 합니다. 선택적 값(Option)과 실패할 수 있는 연산(Result)을 모델링함으로써 개발자들이 null 관련 버그를 피하고 오류를 명시적으로 다룰 수 있도록 도와줍니다. 이러한 타입은 함수형 프로그래밍 패턴을 장려하여 코드의 명확성과 강건성을 향상시킵니다. 이 패키지는 가볍고 모든 주요 플랫폼에서 기존 Dart 프로젝트에 원활하게 통합될 수 있습니다.

사용 사례

  • 널 값 안전하게 처리하기
  • null 확인을 명시적인 Option 사용으로 대체하기
  • 성공/실패 상태로 함수 결과 관리
  • 유연한 오류 처리 로직 작성
  • 다트에서 함수형 프로그래밍 패턴 채택하기

주요 기능

  • Rust와 유사한 Option 타입
  • Rust와 유사한 Result 타입
  • 명시적 처리를 통한 널 안전성
  • 함수형 프로그래밍 유틸리티
  • 크로스 플랫폼 호환성

적합한 대상

  • null의 더 안전한 대안을 찾는 개발자
  • 함수형 프로그래밍 스타일을 채택하는 팀
  • 강력한 오류 관리를 필요로 하는 프로젝트
  • 다중 플랫폼을 대상으로 하는 Dart 애플리케이션
  • 널 참조로 인한 런타임 충돌을 줄이려는 사람

고려 사항

  • 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 개

소스 저장소

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