Skip to content

Instantly share code, notes, and snippets.

View yasuabe's full-sized avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / Chapter07.scala
Last active December 15, 2017 22:01
ch07 apples and oranges
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Gen, Prop, Properties}
object Chapter07 extends Properties("Ch07") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter06.scala
Created December 15, 2017 17:49
ch06 equality for all, redux
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Gen, Prop, Properties}
/*
* Dollar と Franc で共通の Money クラスを作り equalsを引き上げた
* テストコードのは変更はなし
@yasuabe
yasuabe / Chapter05.scala
Created December 15, 2017 16:11
ch5 franc-ly speaking
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Gen, Prop, Properties}
object Chapter05 extends Properties("Ch05") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter04.scala
Created December 15, 2017 15:39
ch04 privacy
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Gen, Properties}
object Chapter04 extends Properties("Ch04") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter03.scala
Created December 15, 2017 15:12
ch03 equality for all
package fp_tdd
import org.scalacheck.Prop.forAll
import org.scalacheck.{Gen, Properties}
object Chapter03 extends Properties("Ch03") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
// Make "amount" private
// Money rounding?
@yasuabe
yasuabe / Chapter02.scala
Created December 15, 2017 15:03
ch02 degenerate objects
package fp_tdd
import org.scalacheck.Prop.forAll
import org.scalacheck.Properties
object Chapter02 extends Properties("Ch02") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
// Make "amount" private
// Money rounding?
@yasuabe
yasuabe / Chapter01.scala
Last active December 15, 2017 21:58
ch01 multi-currency money
package fp_tdd
import org.scalacheck.Prop.forAll
import org.scalacheck.Properties
object Chapter01 extends Properties("Ch01") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
// Make "amount" private
// Dollar side effect
@yasuabe
yasuabe / hylomorphism.sc
Last active March 8, 2019 21:05
階乗とフィボナッチの両方で使えるhylomorphismを書いてみる
import cats.Functor
import cats.syntax.functor._
// hylomorphism -----------------
type Algebra[F[_], B] = F[B] => B
type Coalgebra[F[_], A] = A => F[A]
def hylomorphism[F[_]: Functor, A, B](
alg: Algebra[F, B],
coalg: Coalgebra[F, A])(seed: A): B =
@yasuabe
yasuabe / scenario_test_for_free_service.sc
Last active December 7, 2017 11:10
Free Monadを用いた Serviceコードのシナリオテストの試案
import scala.language.higherKinds
import cats.data.StateT
import cats.free.Free
import cats.~>
import cats.instances.all._
import iota.TListK.:::
import iota.{CopK, TNilK}
import Free.inject
@yasuabe
yasuabe / Simpath.Main.hs
Created May 12, 2017 13:02
haskell implementation of simpath: Main
import System.Environment
import Simpath.Border (borders)
import Simpath.Edge (Edge, edge, modify)
import Simpath.CounterMap
gridEdges :: Int -> [Edge]
gridEdges size = upper ++ lower
where
upper = snd $ foldl (\(c, ts) n -> (c + n, ts ++ edgesAt n c)) (0, []) [1 .. size-1]
where edgesAt n acc = map (+ acc) [1 .. n] >>= addPair