Skip to content

Instantly share code, notes, and snippets.

import shapeless.{::,HList, HNil}
import io.estatico.newtype.macros.newtype
object Learning {
trait Transform[A,B,C,D,K] {
def tx(k: K)(a: A)(f: C => D): B
}
implicit def mapTransform[A,B,K]: Transform[Map[K,A],B,A,B,K] = new Transform[Map[K,A],B,A,B,K] {
import shapeless.{::, HList, HNil}
import io.estatico.newtype.macros.newtype
object Program {
type EntityState =
Map[EID,Name] ::
Map[EID,Might] ::
Map[EID,Magic] ::
@bkyrlach
bkyrlach / example1.scala
Last active February 28, 2019 20:09
Monad examples in Scala
sealed trait MonadOps[M[_]] {
// functor
def pure[A](a: A): M[A]
def map[A,B](ma: M[A])(f: A => B): M[B]
// monad
def flatMap[A,B](ma: M[A])(f: A => M[B]): M[B]
}
case class Id[A](a: A)

Motivation

The underlying motivation for Reader and CategoryTheory revolves around two facts.

  1. Pure functions are easier to reason about.
    • Supports equational reasoning
    • Code only does what it says... no external factors
  2. Pure functions are easier to test.

I'm happy to provide further justification for these facts, but hopefully these assertions are sensible enough to not need that.

using System;
using System.Collections.Generic;
namespace Lesson2
{
class Program
{
static void Main(string[] args)
{
var definitions = new List<string>() { "verb", "verb", "adjective", "noun" };
@bkyrlach
bkyrlach / questions.cs
Created December 2, 2018 14:02
Ask multiple questions...
Console.Write("What is thy name? ");
var name = Console.ReadLine();
Console.Write("What is thy favorite colour? ");
var colour = Console.ReadLine();
object Program {
def f1(x: Int): Either[String,Int] = x match {
case n if n > 3 => Right(n + 2)
case _ => Left(s"$x must be > 3")
}
def f2(x: Int): Either[String,Int] = x match {
case n if n % 2 == 0 => Right(n / 2)
case _ => Left(s"$x must be even")
namespace trampoline.Try3
{
public class Unit
{
public static readonly Unit Only = new Unit();
private Unit() { }
}
public class Trampoline<A, B, C, T>
module Tree where
data Tree a =
Leaf
| Branch (Tree a) a (Tree a)
flatten Leaf = []
flatten (Branch l x r) = (flatten l) ++ [x] ++ (flatten r)
insertOrdered Leaf y = Branch Leaf y Leaf
module Intro where
import Data.Char (toUpper)
x = 3
greeting = "Hello"
three :: () -> Int
three _ = 3