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 org.scalatest.wordspec.AnyWordSpec | |
import org.scalatest.matchers.should.Matchers | |
import language.experimental.fewerBraces | |
class SampleSpec extends AnyWordSpec: | |
"A Set" when: | |
"empty" should: | |
"have size 0" in: |
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
implicit def EitherDecoder[L: Decoder, R: Decoder]: Decoder[Either[L, R]] = | |
Decoder[R].map(Right.apply) or Decoder[L].map(Left.apply) | |
implicit def EitherEncoder[L: Encoder, R: Encoder]: Encoder[Either[L, R]] = { | |
case Left(l) => Encoder[L].apply(l) | |
case Right(r) => Encoder[R].apply(r) | |
} |
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 RankNTypes #-} | |
import Data.IORef | |
import System.IO.Unsafe (unsafePerformIO) | |
newtype ST s a = ST | |
{ unsafeRunST :: a | |
} | |
instance Functor (ST s) 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
{-# LANGUAGE GADTs #-} | |
module Main where | |
data Exp r where | |
Const :: (Show r) => r -> Exp r | |
Add :: (Num r) => Exp r -> Exp r -> Exp r | |
Subtract :: (Num r) => Exp r -> Exp r -> Exp r | |
Eq :: (Eq r) => Exp r -> Exp r -> Exp Bool | |
And :: Exp Bool -> Exp Bool -> Exp Bool |
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 GeneralizedNewtypeDeriving #-} | |
module Main where | |
import Control.Applicative | |
import Control.Monad.Identity | |
import Control.Monad.Reader | |
import Control.Monad.Writer | |
data Config = |
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
object InvertibleScramble { | |
def scramble(value: Int): Int = { | |
require(value > 0) | |
def f = | |
multiplyOdd1 andThen | |
trim andThen | |
reverse andThen |
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
type A=Int;type B=Seq[A] | |
def f(n:A,r:A,a:B=Nil):B=if(n<=0)a else f(n/r,r,n%r+:a) | |
def g(n:B)=n==n.reverse | |
def h(n:A):A=if(g(f(n,2))&&g(f(n,8))&&g(f(n,10)))n else h(n+1) | |
print(h(10)) |