Skip to content

Instantly share code, notes, and snippets.

@stumash
stumash / byname.scala
Last active Feb 3, 2021
by-name function calls in scala
View byname.scala
object ByName {
/**
* So-called 'by name' function parameters are basically automatically wrapped in thunks
*
* how 'by name' function are desugared:
*
* def f(x: => Int): Int = { x; x }
* f( { println("once"); 1 } )
*
* desugars to
@stumash
stumash / co_and_contra_variance.scala
Last active Apr 8, 2020
scala covariance and contravariance
View co_and_contra_variance.scala
import scala.collection.mutable.ArrayDeque
object Co_and_Contra_Variance {
def main(args: Array[String]): Unit = {
theBasicIdea() // - What covariance and contravariance let you do, without discussing why or how
theCoreConceptIsBasedOnFunctions() // - How do we decide if function f1 can be substituted by f2? (aka f2 is subtype of f1)
bringItAllTogether() // - Now that we know why and how, let's see how it applies
}
def theBasicIdea(): Unit = {
@stumash
stumash / VirtualenvQuickGuide.md
Last active Sep 21, 2018
python virtualenv as fast as possible
View VirtualenvQuickGuide.md

Create a virtualenv

make a virtualenv in a directory called vdir with:

$ virtualenv vdir [-p pythonX.X]

Activate a virtualenv

start using the virtualenv in vdir with:

$ source vdir/bin/activate