Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 437 Bytes

README.md

File metadata and controls

22 lines (16 loc) · 437 Bytes

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")