This file contains 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 sample; | |
import java.util.Map; | |
/** | |
* | |
*/ | |
public class GoodCodeRed<V> { | |
public <K> Map<K, V> test(K k) { |
This file contains 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
$ scalac sample.scala | |
sample.scala:14: error: applyDynamic does not support passing a vararg parameter | |
new Foo().foo(xs:_*).foobar(new Bar().bar) | |
^ | |
one error found |
This file contains 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
object Sample { | |
def unapply(i: Int): Option[String] = Some(i.toString) | |
def run(): Unit = (0: Short) match { | |
case Sample(r) => println(r) | |
} | |
} |
This file contains 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 scala.slick.session.Database | |
import scala.slick.driver.H2Driver.simple._ | |
case class Club(name: String, id: Option[Long] = None) | |
case class Student(name: String, classroom: String, clubId: Option[Long], id: Option[Long] = None) | |
trait DAO { |
This file contains 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 io.netty.buffer.{Unpooled, ByteBuf} | |
import java.nio.charset.Charset | |
object NettyUtil { | |
implicit class ByteBufOps(val buf: ByteBuf) extends AnyVal { | |
def getUTF(index: Int): String = { | |
val length = buf.getUnsignedShort(index) | |
sliceToString(index + 2, length) |
This file contains 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 Option {} | |
class Some extends Option { | |
constructor(value) { | |
this.value = value; | |
} | |
function map(f) { | |
return ::Some(f(value)); | |
} |
This file contains 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 ACGT = "ACGT".to[Stream] | |
@annotation.tailrec | |
def solve0(n: Int, ss: Stream[List[Char]]): Stream[List[Char]] = | |
if (n == 0) ss | |
else solve0(n - 1, ACGT.flatMap(c => ss.map(c :: _))) | |
def solve(n: Int): Stream[String] = | |
solve0(n, Stream(Nil)) collect { | |
case cs if cs.containsSlice("AAG") => cs.mkString |
This file contains 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
object Sample extends App { | |
val seq = Seq(1, 2, 3) | |
val empty = Seq[Int]() | |
println(seq.max) // -> 3 | |
// println(empty.max) // -> java.lang.UnsupportedOperationException: empty.max | |
import scalaz._, Scalaz._ |
This file contains 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 sample.plugin.google | |
import com.intellij.openapi.actionSystem.{PlatformDataKeys, AnAction, AnActionEvent} | |
import com.intellij.ide.BrowserUtil | |
import java.io.UnsupportedEncodingException | |
import java.net.URLEncoder | |
import scala.util.control.Exception._ | |
class GoogleSearchAction extends AnAction { |
This file contains 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
scala> trait DateOrdering extends scala.math.Ordering[java.util.Date] { | |
| def compare(x: java.util.Date, y: java.util.Date) = x.compareTo(y) | |
| } | |
defined trait DateOrdering | |
scala> implicit object Date extends DateOrdering | |
defined module Date | |
scala> List(new java.util.Date()).min | |
res6: java.util.Date = Fri Apr 15 15:16:18 JST 2011 |
NewerOlder