Skip to content

Instantly share code, notes, and snippets.

@phdoerfler
Last active April 20, 2021 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phdoerfler/fe287cb416daa4edffe9fdc652b013c3 to your computer and use it in GitHub Desktop.
Save phdoerfler/fe287cb416daa4edffe9fdc652b013c3 to your computer and use it in GitHub Desktop.
Scala

PartialFunction

import scala.{PartialFunction => =/>}
val mapper: String =/> String = {
  case Header(s) => s
}
val totalMapper = mapper orElse (identity[String] _): String =/> String
val totalMapper2 = mapper orElse PartialFunction.fromFunction(identity[String] _)

With RegEx

val Header = """>> (.*)""".r
sectioned.map(_.collect((Header.findFirstIn _).unlift))
sectioned.map(_.collect(Function.unlift(Header.findFirstMatchIn)))

case class <=> Tuple

Tuple => case class

(Section.apply _).tupled

case class => Tuple

CompanionObject.unapply(...).get

Bonus

Shapeless

Libraries

specs2

libraryDependencies ++= specs2("4.10.0", Seq("core", "html", "scalacheck"))

def specs2(version: String, features: Seq[String]) =
  features.map(fe => "org.specs2" %% f"specs2-$fe%s" % version % "test")

scalacOptions in Test += "-Yrangepos" // specs2

testOptions in Test += Tests.Argument("console")
testOptions in Test += Tests.Argument("html")

Docs

import org.specs2._

class QuickStartSpec extends Specification { def is = s2"""

This is my first specification
  it is working                 $ok
  really working!               $ok
                                """
}

Docs

Specs2 Linking other specs

${"A user may " ~ ("press the button ", new ButtonSpec, "to turn on the blender.")}

Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment