Skip to content

Instantly share code, notes, and snippets.

View tomwadeson's full-sized avatar

Tom Wadeson tomwadeson

View GitHub Profile
scala> case class Callback[A](f: (A => Unit) => Unit) {
| def map[B](g: A => B): Callback[B] = Callback { (h: B => Unit) => f(a => h(g(a))) }
| def flatMap[B](g: A => Callback[B]): Callback[B] = Callback { (h: B => Unit) => f(a => g(a).f(b => h(b))) }
| }
defined class Callback
module HarryPotter where
import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes)
type Copies = Int
type Discount = Double
type Price = Double
type DiscountScheme = Int -> Discount
package com.tomwadeson.show
import com.tomwadeson.Show.Showable
import scala.language.implicitConversions
trait Show[A] {
def show(a: A): String
}
module IntermediateHaskellExercises where
class Fluffy f where
furry :: (a -> b) -> f a -> f b
-- Exercise 1
instance Fluffy [] where
furry :: (a -> b) -> [a] -> [b]
furry _ [] = []
furry f (x:xs) = f x : furry f xs

Keybase proof

I hereby claim:

  • I am tomwadeson on github.
  • I am tomwadeson (https://keybase.io/tomwadeson) on keybase.
  • I have a public key ASBHtwj-BohXckvgbTfHp9M5a79ZrcLg8_WrLEQS07qrvgo

To claim this, I am signing this object:

import cats.effect.{ExitCode, IO, IOApp, Resource}
import org.http4s.HttpRoutes
import org.http4s.client.Client
import org.http4s.client.blaze.BlazeClientBuilder
import org.http4s.dsl.Http4sDsl
import org.http4s.implicits._
import cats.implicits._
object Http4sClientTest extends IOApp {
trait Console[F[_]] {
  def readLine: F[String]
  def printLine(s: String): F[Unit]
}
// I know that all this function can do is call `readLine`.
// What's more, it can only do it exactly (usefully) once.
@tomwadeson
tomwadeson / FooRepository.scala
Created November 5, 2019 16:56
A demonstration of specifying a `FooRepository` capability and ensuring that in-memory and postgres-based interpreters are compliant
package foo
import cats.effect.{IO, Resource, Sync}
import cats.effect.concurrent.Ref
import cats.implicits._
import doobie.util.transactor.Transactor
/**
* The `Foo` domain model.
*
@tomwadeson
tomwadeson / ArbitraryStreams.scala
Last active November 15, 2019 00:35
Streaming generation of arbitrary (and optionally distinct) data, with a scary-looking `toIterator` to integrate with Gatling
package newbeeper.performance
import cats.effect.concurrent.{MVar, Ref}
import cats.effect.syntax.concurrent._
import cats.effect.{Concurrent, ConcurrentEffect, Sync}
import cats.syntax.flatMap._
import cats.syntax.functor._
import fs2.Stream
import org.scalacheck.Arbitrary
@tomwadeson
tomwadeson / Day1.hs
Created February 17, 2020 09:45
Advent Of Code 2019, Day 1
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module Day1
( moduleMasses
, partOne
, partTwo
)
where