Skip to content

Instantly share code, notes, and snippets.

View frekw's full-sized avatar
🐼

Fredrik Wärnsberg frekw

🐼
  • https://www.soundtrackyourbrand.com/
  • Stockholm, Sweden
  • 23:31 (UTC +01:00)
View GitHub Profile
def foldZIO[A, E] = new PartialFoldZIO[A, E](())
final class PartialFoldZIO[A, E](val unit: Unit) extends AnyVal {
def apply[R, E1, A0, B](
onError: E => ZIO[R, E1, B],
onDefect: Throwable => ZIO[R, E1, B],
onSuccess: A => ZIO[R, E1, B],
): Middleware[R, E1, A0, A, A, B] = new Middleware[R, E1, A0, A, A, B] {
override def apply[R1 <: R, E2 >: E1](http: Http[R1, E2, A0, A]): Http[R1, E2, A0, B] = {
http.foldHttp(
def accessLogger[R, E](
next: Http[R, E, Request, HttpResponse[R, E]]
): HttpApp[R with clock.Clock with Logging, E] = {
Http.flatten {
Http.fromEffectFunction[Request] { req =>
val path = req.url.path
val method = req.method
clock.instant.flatMap(start => {
val logSuccess = (resp: HttpResponse[R, E]) => {
@frekw
frekw / Exector.scala
Last active April 6, 2021 10:51
Caliban remote schemas
package gql.remoteschema
import zio._
import zio.query._
import caliban._
import caliban.schema._
import caliban.introspection.adt._
import caliban.execution.Field
import gql.remoteschema.json._
package zio_grpc.examples.helloworld
import io.grpc.Status
import scalapb.zio_grpc.ServerMain
import scalapb.zio_grpc.ServiceList
import scalapb.zio_grpc.{RequestContext, ZTransform}
import zio._
import zio.console._
import zio.stream._
@frekw
frekw / zio-intro.scala
Created October 8, 2020 09:29
ZIO Intro
package example
import zio._
import zio.console
import zio.random._
import zio.duration._
import zio.clock
import scala.concurrent.Future
// What _is_ ZIO?
function useAsync() {
const [fn, setFn] = useState(null);
const [state, setState] = useState({
loading: false,
data: null,
error: null
});
const lastCallId = useRef(0);
useEffect(() => {
defmodule Producer do
require Logger
use GenStage
def start_link([]) do
Logger.info("starting producer")
GenStage.start_link(__MODULE__, :ok, name: __MODULE__)
end
def init(:ok) do
# vi-like navigation setw -g mode-keys vi
# mouse control for panes
set -g mouse on
# don't rename windows automagically
set-option -g allow-rename off
# start windows numbering at 1 and rename on window close
setw -g pane-base-index 1
set -g base-index 1
type timerID;
[@bs.val] external setInterval: (unit => unit, int) => timerID = "setInterval";
[@bs.val] external clearInterval: timerID => unit = "clearInterval";
module Counter = {
let component = ReasonReact.component("Counter");
let make = (~initial = 0, _children) => {
...component,
render: _self => {
let (count, setCount) = ReactHooks.useState(initial);
defmodule Forma do
# defmacro __using__([]) do
# quote do
# import Forma, only: [forma: 2]
# end
# end
# defmacro forma(name, module) do
# module = Macro.expand(module, __CALLER__)
# transform = Forma.compile_module(module)