I am doing some exercise from the book Grokking Functional Programming, the origin code examples are written in Scala, and I want to rewrite it with Raku.
In Scala's cats effect library, there is a type call IO, which is a data type for encoding side effects as pure values, capable of expressing both synchronous and asynchronous computations.IO[A]
is a value that represents a potentially side-effectful
IO action (or another unsafe operation) that, if successful,
produces a value of type A.
The following code print "hey!" twice:
import cats.effect.IO
import cats.effect.unsafe.implicits.global
object TestApp extends App {
val program: IO[Unit] = for {
_ <- IO.println("hey!")
_ <- IO.println("hey!")
} yield ()
program.unsafeRunSync()
}
The code can be run in Scala playground.
The corresponding data type in Raku I can think of is Promise, or some other Lazy data type I dont't know yet.
So, does Raku has a data type for encoding side effects as pure values?
_ <- IO.println("hey1!")
to_ <- IO.println("hey9!")
, then ran it many times. Each time the lines were executed in order. I wanted to sprinklesleep
like delays between some lines to see what that did, but after about 10 minutes of failing to figure out how to do that (eg this didn't help) I fell asleep. – Tem_ <- IO. sleep(5.seconds)
to sleep some seconds, when youimport scala.concurrent.duration._
– Sherard