Skip to content

Instantly share code, notes, and snippets.

@kartoffelsup
Last active February 16, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kartoffelsup/f749e2b1d0078a252204cfee82397463 to your computer and use it in GitHub Desktop.
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'
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