tabdulradi / happypath

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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

License:Apache License 2.0


Languages

Language:Scala 100.0%