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
license: gpl-3.0 | |
height: 600 |
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 java.util | |
import org.apache.kafka.clients.consumer.KafkaConsumer | |
import scala.collection.JavaConverters._ | |
object ConsumerExample extends App { | |
import java.util.Properties |
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 scala.util.Random | |
// Simple example of an IO effect Monad, no Cats | |
object MyIO extends App{ | |
// IO encapsulates a side effecting operation | |
final class IO[A](val run: () => A) { | |
def map[B](f: A => B): IO[B] = IO(f(run())) |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"sync" | |
"time" | |
"unsafe" | |
) |
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func greet(st string, done chan bool) { | |
fmt.Println(st) | |
done <- true |
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
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
// Maps over collection of T and applies function f to each item | |
// Returns a new slice with the transformed items | |
func mapf[T any, U any](items []T, f func(T) U) []U { |
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 zio._ | |
object FakeConsoleExample extends ZIOAppDefault { | |
private val program = ZIO.serviceWithZIO[Console] { console => | |
for { | |
_ <- console.printLine("Going to the grocery store") | |
input <- console.readLine("How are you? ") | |
_ <- console.printLine(s"You said: $input") | |
} yield () |
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 zio._ | |
import scala.{ Console => SConsole } | |
import scala.io.StdIn | |
import java.io.{ BufferedReader, IOException } | |
import scala.util.Try | |
object InterruptableReadLine extends ZIOAppDefault { | |
def altReadLine(reader: BufferedReader = SConsole.in) = | |
ZIO |
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 scala.annotation.targetName | |
import scala.util.boundary | |
import scala.util.boundary.{Label, break} | |
// Works in Scala 3.4.1 | |
def firstIndex[T](xs: List[T], p: T): Int = { | |
boundary: | |
for (x, i) <- xs.zipWithIndex do if (x == p) break(i) | |
-1 |
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
async fn hello(name: &str) -> String { | |
// pretend to be doing some work | |
tokio::time::sleep(std::time::Duration::from_secs(1)).await; | |
format!("Hello {}", name) | |
} | |
fn blocking() -> String { | |
println!("Blocking"); |
NewerOlder