-
-
Save kartoffelsup/f749e2b1d0078a252204cfee82397463 to your computer and use it in GitHub Desktop.
Yields a 'Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class arrow.core.Either$Left'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arrow.Kind | |
import arrow.core.Try | |
import arrow.data.ListK | |
import arrow.data.extensions.list.traverse.traverse | |
import arrow.data.fix | |
import arrow.effects.IO | |
import arrow.effects.extensions.io.applicativeError.attempt | |
import arrow.effects.extensions.io.fx.fx | |
import arrow.effects.typeclasses.suspended.concurrent.Fx | |
enum class ServiceResult { | |
SUCCESS, ERROR | |
} | |
class SomeService<F>(private val M: Fx<F>) { | |
private suspend fun putStrLn(str: String) = println(str) | |
fun doIt(int: Int): Kind<F, ServiceResult> = | |
M.fx { | |
Try { | |
Thread.sleep(1L) | |
throw IllegalStateException("foo") | |
} | |
.fold( | |
{ | |
!effect { | |
putStrLn("Error: foo bar $int") | |
} | |
ServiceResult.ERROR | |
} | |
, { | |
ServiceResult.SUCCESS | |
}) | |
} | |
} | |
class Program<F>(private val M: Fx<F>) { | |
fun doIt(): Kind<F, ListK<ServiceResult>> = M.fx { | |
val someService = SomeService(M) | |
(1..500).toList() | |
.traverse(M.concurrent(), { someService.doIt(it) }).bind() | |
.fix() | |
} | |
} | |
fun main() { | |
Program(IO.fx()).doIt().attempt().unsafeRunSync() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment