nidula 0.0.3 copy "nidula: ^0.0.3" to clipboard
nidula: ^0.0.3 copied to clipboard

A lightweight Dart library for Rust-like Option/Result types. Supports exhaustive pattern matching and compile-time safe, chainable None/Err propagation.

example/nidula_example.dart

import 'package:nidula/nidula.dart';

Result<double, String> example(Result<double, String> r) {
  return Result.catchProp<double, String>((t) {
    r = Ok(r.prop(t) / 2);
    return Ok(r.prop(t));
  });
}

void main() {
  print('#1: ${example(Err('s'))}'); // #1: Err(s)
  print('#2: ${example(Ok(14))}'); // #2: Ok(7.0)

  print(Result.catchProp<I, String>((t) {
    return Ok(Ok<I, String>(I())(t).make()(t).make()(t));
  }));
}

class I {
  Result<I, String> make() {
    return Ok(I());
  }
}
6
likes
0
pub points
17%
popularity

Publisher

verified publishermanuelplavsic.ch

A lightweight Dart library for Rust-like Option/Result types. Supports exhaustive pattern matching and compile-time safe, chainable None/Err propagation.

Repository (GitLab)
View/report issues

Topics

#option #result #pattern-matching #try-operator

License

unknown (license)

More

Packages that depend on nidula