It is annoying to always unwrap a value from an Either only to be forced to handle the failure case.
Replace the Either value of the failure case with throwing an exception:
// ...
if (numberOfSeats > 1) {
Right(makeReservation(numberOfSeats))| import cats.data.State | |
| object PRNG { | |
| final case class Seed(seed: Long) { | |
| private lazy val next = Seed(seed * 6364136223846793005L + 1442695040888963407L) | |
| def nextInt: (Seed, Int) = { | |
| (next, (next.seed >>> 16).asInstanceOf[Int]) | |
| } |
| <#@ template debug="false" hostspecific="false" language="C#" #> | |
| <#@ assembly name="System.Core" #> | |
| <#@ import namespace="System.Linq" #> | |
| <#@ import namespace="System.Text" #> | |
| <#@ import namespace="System.Collections.Generic" #> | |
| <#@ output extension=".cs" #> | |
| //------------------------------------------------------------------------------ | |
| // <auto-generated> | |
| // This code was generated by a tool. | |
| // |
| module Siren | |
| open System | |
| open Hypermedia.Models | |
| type Rel = Rel of string | |
| type Title = Title of string | |
| type Class = Class of string | |
| type MediaType = MediaType of string |
| #load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs" | |
| type Continuation<'output, 'next> = 'output -> 'next | |
| module TerminalDsl = | |
| open Chessie.ErrorHandling | |
| type Terminal<'next> = | |
| | WriteLine of string * Continuation<unit, 'next> | |
| | ReadLine of unit * Continuation<string, 'next> |
| [<AutoOpen>] | |
| module IO = | |
| type IO<'a> = | |
| private | |
| | Return of (unit -> 'a) | |
| | Suspend of (unit -> IO<'a>) | |
| let rec run x = | |
| match x with | |
| | Return v -> v() |
| #load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs" | |
| open System | |
| open Chessie.ErrorHandling | |
| type Person = { FirstName: string; LastName: string } | |
| let id1 = Guid.NewGuid() | |
| let id2 = Guid.NewGuid() |
| package futureeitherapplicativestack | |
| import cats._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| import scala.concurrent.{Await, Future} | |
| import scala.concurrent.duration.Duration | |
| import scala.concurrent.ExecutionContext.Implicits.global |
| public class EditedPair<T> | |
| { | |
| public EditedPair(T old, T @new) | |
| { | |
| Old = old; | |
| New = @new; | |
| } | |
| public T Old { get; private set; } | |
| public T New { get; private set; } |