Skip to content

Instantly share code, notes, and snippets.

View yasuabe's full-sized avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / RegisterAFP3.sc
Created December 19, 2017 06:23
by eff monad
import cats.data.{State, Writer}
import org.atnos.eff._
import org.atnos.eff.state._
import org.atnos.eff.writer._
import org.atnos.eff.syntax.all._
case class CashRegister(total: Int) {
def addCash(toAdd: Int) = CashRegister(total + toAdd)
}
type Purchase = CashRegister => CashRegister
@yasuabe
yasuabe / RegisterAFP2.sc
Created December 19, 2017 06:22
by state monad
import cats.data.State
case class CashRegister(total: Int) {
def addCash(toAdd: Int) = CashRegister(total + toAdd)
}
type Purchase = CashRegister => CashRegister
def makePurchase(amount: Int): Purchase = (r: CashRegister) => {
println("Purchase in amount: " + amount)
r addCash amount
}
@yasuabe
yasuabe / RegisterAFP.sc
Created December 19, 2017 06:19
by writer monad
import cats.data.Writer
import cats.instances.vector._
import cats.syntax.writer._
case class CashRegister(total: Int) {
def addCash(toAdd: Int) = CashRegister(total + toAdd)
}
type Purchase = CashRegister => CashRegister
def makePurchase(amount: Int): Purchase = (r: CashRegister) => {
println(s"Purchase in amount: $amount")
@yasuabe
yasuabe / Chapter16.scala
Last active December 15, 2017 21:59
ch15 mixed concurrencies - ch16 abstraction finally
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter16 extends Properties("ch16") {
// ======== TODO ========
// ======== DONE ========
@yasuabe
yasuabe / Chapter14.scala
Created December 15, 2017 19:13
ch14 change
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter14 extends Properties("Ch14") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter13.scala
Created December 15, 2017 19:00
ch14 make it
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter13 extends Properties("Ch13") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter12.scala
Created December 15, 2017 18:36
ch12 addition finally
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter12 extends Properties("Ch12") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter10.scala
Last active December 15, 2017 22:00
ch10 interesting times- ch11 the root of all evil
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter10 extends Properties("Ch10") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter09.scala
Last active December 15, 2017 22:00
ch09 times we're living in
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter09 extends Properties("Ch09") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1
@yasuabe
yasuabe / Chapter08.scala
Created December 15, 2017 18:11
ch08 makin' objects
package fp_tdd
import cats.Apply
import cats.syntax.apply._
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen, Properties}
object Chapter08 extends Properties("Ch08") {
// ======== TODO ========
// $5 + 10 CHF = $10 if rate is 2:1