This file contains hidden or 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
// We can re-use a simple function that goes from Time to a new Time | |
val adjustTime: DateTime => DateTime = ??? | |
// With an appropriate traversal in scope we can apply the adjustTime function from this library to any incoming holder | |
def adjustTimes[T](implicit T: Traversal[T, DateTime]): T => T = | |
T.modify(adjustTime) | |
// Again we can keep a concrete alternative to adjustTime, we just increment it by duration: | |
def increaseTimeBy(duration: FiniteDuration): DateTime => DateTime = | |
_.add(duration) |
This file contains hidden or 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
val BalanceSheetId: Lens[BalanceSheet, DatabaseID] = | |
GenLens[BalanceSheet](_.id) | |
def save(sheet: BalanceSheet): IO[DatabaseID] = ??? | |
//Updates a given sheet with the new id from the database | |
def store(sheet: BalanceSheet): IO[BalanceSheet] = | |
save(sheet).map(BalanceSheetId.set(_)(sheet)) |
This file contains hidden or 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 cats.{Bifoldable, Eq, Foldable, Show} | |
import cats.data.Ior | |
import cats.instances.either._ | |
import cats.instances.option._ | |
import cats.instances.list._ | |
import cats.syntax.bifoldable._ | |
import cats.syntax.foldable._ | |
import cats.syntax.align._ | |
object DiffExample { |
This file contains hidden or 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
def sumOfAllNumbers(): Int = | |
Array(10,20,30,40,50).sum | |
// -- sanity check | |
sumOfAllNumbers() == 150 | |
def evenElements[A](ls: List[A]): List[A] = | |
ls.view.zipWithIndex.filter(_._2 % 2 == 1).map(_._1).toList | |
// -- sanity check |
This file contains hidden or 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
def sumOfAllNumbers(): Int = { | |
var numbers = Array(10,20,30,40,50); | |
var N:Int=0; | |
var sum: Int=0; | |
for ( N <- numbers ) { | |
sum+=N; | |
} | |
sum | |
} | |
// -- sanity check |
This file contains hidden or 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
/* | |
* This file has the setup and boilerplate. | |
* how to calculate the pay for a teacher, and the fee for a student. | |
* how to find the student or teacher just from a name string, and a | |
* `List` of names. | |
*/ | |
type Fee = Double | |
type Pay = Double | |
type Balance = Double |
This file contains hidden or 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
class BalanceSheet { | |
val froms: List[Transaction] | |
val toss: List[Transaction] | |
/* ... */ | |
} | |
class Transaction { | |
val issue: DateTime | |
val acknowledge: DateTime | |
/* ... */ |
This file contains hidden or 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
package industrious | |
import io.dylemma.spac.xml._ | |
import org.specs2.{ScalaCheck, Specification} | |
import org.scalacheck.{Gen, Prop} | |
class SvnXmlParserSpec extends Specification with ScalaCheck { | |
def is = s2""" | |
SVN XML Parser can | |
parse entries $parseEntries |
This file contains hidden or 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
#!/usr/bin/env amm | |
import $plugin.$ivy.`org.typelevel:::kind-projector:0.11.0` | |
import $ivy.{ | |
`co.fs2::fs2-core:2.0.1`, | |
`com.github.julien-truffaut::monocle-generic:2.0.0` | |
} | |
import cats.Applicative | |
import fs2._ | |
import monocle._ |
This file contains hidden or 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
#!/usr/bin/amm | |
import $ivy.`org.scalaz::scalaz-core:7.2.18` | |
import $ivy.`com.slamdata::matryoshka-core:0.18.3` | |
import scala.annotation.tailrec | |
sealed trait Tree[+A] | |
object Tree { |