Giter Club home page Giter Club logo

p5-result's Introduction

NAME

Result - ripoff rust result

SYNOPSIS

use Result qw/Ok Err try_result/;

sub do_the_thing {
  try_result { activity_that_may_die() }
    ->and_then(\&activity_returning_result)
}

sub activity_that_may_die {
  die 'ack!' if rand > 0.8;
  return 17 if rand > 0.9;
  84
}

sub activity_returning_result {
  my ($in) = @_;
  return Ok($in / 2) if $in % 2 == 0;
  Err('Odd numbers are gross');
}

do_the_thing()->expect('Failed to do thing');

STATUS

Not released to CPAN.

DESCRIPTION

This project is an experiment copying some of the behavior of Rust's Result enum to Perl. Of course you don't get some of the benefits of the type system, but the idea is to force error handling, without throwing exceptions, while offering chained control flow. I decided to build it out to see how it feels in action.

Other than Ok() and Err() constructors for the two result cases, try_result {} is available to catch an exception and turn it into an Err($e).

p5-result's People

Contributors

merrilymeredith avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.