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
'use strict'; | |
const R = require('ramda'); | |
const rules = {"&": [ | |
{">": [ "!products.blah", 2 ]}, | |
{">": [ "!products.meow", 1 ]} | |
]}; | |
const basket = { products: { meow: 2, blah: 3 } }; |
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
'use strict'; | |
const R = require('ramda'); | |
/* | |
* Mathematically, Monoids are a SemiGroup with an identity element. | |
* | |
* Monoids are defined under a certain operation, they require 3 things: | |
* the operation must be associative, so op(op(A,B),C) == op(A,op(B,C)) | |
* an identity (sometimes called the Zero) such that type op(A, I) = A and op(I, A) = A, |
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 play.api.libs.json._ | |
sealed trait Color | |
object Color { | |
type Red = Red.type | |
type Green = Green.type | |
type Blue = Blue.type | |
case object Red extends Color | |
case object Green extends Color |
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 com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials} | |
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration | |
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder | |
import com.amazonaws.services.dynamodbv2.model._ | |
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType._ | |
import scala.collection.convert.decorateAsJava._ | |
val credentials = new BasicAWSCredentials("dev", "dev") | |
val credProvider = new AWSStaticCredentialsProvider(credentials) | |
val endpointConfiguration = new EndpointConfiguration("http://localhost:8000", "local") |
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.language.higherKinds | |
import cats.Functor | |
import cats.implicits._ | |
/* | |
* A Free Functor is a Functor definition that doesn't care what F[_] is. | |
* We are Free from having to know about F[_] until we run() it. | |
* It uses the second Functor Law: fmap (g . f) = fmap g . fmap f | |
* FreeF is just a container that composes functions | |
* When you run it, you give it an actual container and the intial value |
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
sealed trait Json | |
case class JsonString(value: String) extends Json | |
sealed trait Yaml | |
case class YamlString(value: String) extends Yaml | |
object Symbols { | |
type |>[From, To] = Converter[From, To] | |
type <|[To, From] = Converter[From, To] | |
} |
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
// From http://milessabin.com/blog/2011/06/09/scala-union-types-curry-howard/ | |
type ∧[A, B] = A with B | |
type ¬[A] = A => Nothing | |
type ¬¬[A] = ¬[¬[A]] | |
type ∨[A, B] = ¬[¬[A] ∧ ¬[B]] // De Morgan equivalence | |
type <|[X, T] = ¬¬[X] <:< T // lift and check subtype | |
def size[T: ? <| (Int ∨ String)](t: T): Int = | |
t match { |
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
{-# LANGUAGE GADTs, DataKinds, TypeFamilies, FlexibleInstances #-} | |
-- from my stackoverflow question: https://stackoverflow.com/questions/40939508/translate-a-scala-type-example-to-haskell | |
data Status = Open | Closed deriving(Show) | |
data Door (status :: Status) = Door | |
--OpenDoor :: Door Open | |
--ClosedDoor :: Door Closed |
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 Data.List | |
quicksort :: Ord a => [a] -> [a] | |
quicksort [] = [] | |
quicksort xs = quicksort lessThanPivot ++ equalToPivot ++ quicksort greaterThanPivot | |
where | |
(lessThanPivot, equalToPivot, greaterThanPivot) = epart (head xs) xs | |
epart :: Ord a => a -> [a] -> ([a], [a], [a]) | |
epart n xs = inner ([], [], []) xs | |
where |
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
<html> | |
<body> | |
<canvas id="canvas1" width="500", height="500"> | |
Random Canvas | |
</canvas> | |
<script type="text/javascript"> | |
element = document.getElementById("canvas1"); | |
c = element.getContext("2d"); |
OlderNewer