Git Product home page Git Product logo

experiment-kotlin-error-handling's Introduction

Why?

TODO: flesh this section out. For now, read this.

What?

TODO: flesh this section out. For now, see main.kt for example usage as well as implementation.

Why not X, Y, Z?

Q: Why not use the Kotlin Result type?

A: For now, the Kotlin Result type is not allowed as a direct result type of Kotlin functions.

Q: Why not use kittinunf.result?

A: The kittinunf.result library great, and was definitely an inspiration for this implementation. One main difference is that kittinunf.result seeks to wrap Exception types inside the Failure, while this seeks to allow any user defined type inside wrapped inside the Failure type. This allows us to use a sealed class to enumerate a finite set of failure scenarios, which can then be more precisely used for local handling of the failures. This is especially powerful when combined with a when assignment, which enables the compiler to check that we are accounting for all the scenarios exhaustively

Q: Why not use Arrow?

A: If you need something more fully featured, you should definitely consider Arrow! Arrow's Either data type is essentially the same concept as the Outcome type demoed in this repo - though Arrow is much more fully featured, and using more idiomatic functional programming terminology:

  • Either:Outcome
  • Left:Failure
  • Right:Success

Demo

Kotlin needs to be installed

$ brew update
$ brew install kotlin

Build & run

$ kotlinc main.kt -include-runtime -d program.jar && java -jar program.jar

Inspiration

TODO

  • Set this up as a proper library

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.