tabdulradi / happypath   0.3.0

Apache License 2.0 GitHub

Makes union types work with for-comprehensions (like scala.Either, but without the allocation cost).

Scala versions: 3.x

happypath

Makes union types work with for-comprehensions (like scala.Either, but without the allocation cost).

Usage

import com.abdulradi.happypath.UnhappyCase

enum AppError derives UnhappyCase:
  case Err1(foo: String)
  case Err2(bar: Int)

@main def app(): Unit = 
  val intOrErr: AppError | Int = 42
  val strOrErr: AppError | String = "test"

  for 
    i <- intOrErr 
    s <- strOrErr
  do println(s"$s $i")