Skip to content

Instantly share code, notes, and snippets.

View martinprobson's full-sized avatar

Martin Robson martinprobson

  • Brighton, UK
View GitHub Profile
@martinprobson
martinprobson / User.scala
Created September 29, 2019 11:25
Scala Extractor (unapply)
package net.martinprobson.scala.Extractors
trait User
class StandardUser(val firstName: String, val lastName:String) extends User
object StandardUser {
def unapply(s: StandardUser): Option[(String, String)] = Some((s.firstName,s.lastName))
}
@martinprobson
martinprobson / Main.scala
Created May 21, 2018 18:05
JIT DI in Scala and Google Guice
import com.google.inject.{AbstractModule,Guice,Inject,ImplementedBy}
/*
This example shows how just in time (JIT) DI injection works in Google guice.
*/
object Main extends App {
//
// First, let us create an injector with a specific binding.
//
@martinprobson
martinprobson / VIM_Hints.md
Last active March 17, 2018 14:36
VIM HInts and Tips

Vim Hints and Tips

A random collection of useful vim commands, hints and features.

1 Use %:h/new_filename to create a new file in the same directory as the current file being edited.

  • % - represents the current file
  • %:h is a modifier for the current file directory
@martinprobson
martinprobson / func.md
Last active March 27, 2018 19:41
Functional Programming Notes
@martinprobson
martinprobson / ImplicitConversions.md
Last active March 5, 2018 16:04
Implicit Conversions and Parameters in Scala

Implicit Conversions in Scala

Summary

Very simple example showing how implicit conversions work in Scala.

Implicit Conversion Example

Let's try converting a StringBuffer into a List of characters.

Note We are using StringBuffer here instead of String because implicit conversion from String to List is already supported as standard in the Scala PreDef object. If we used String it would break rule 3 below.