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 com.example.android2111.app; | |
import java.util.List; | |
import retrofit2.Call; | |
import retrofit2.Retrofit; | |
import retrofit2.http.GET; | |
import retrofit2.http.Path; | |
import retrofit2.converter.gson.GsonConverterFactory |
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
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
trait Context | |
object Helper { | |
def stuff(implicit c: Context) = 3 | |
def stuff_=(i: Int)(implicit c: Context) = () | |
// woot |
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 Str(val str: String) extends AnyVal { | |
def isEmpty = str == null || str.isEmpty | |
def _1 = str.charAt(0) | |
def _2 = str.substring(1) | |
} | |
object Str { | |
def unapply(str: String): Str = new Str(str) | |
} | |
object StrTest { |
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
object MySorts extends Ordering.ExtraImplicits { | |
def mergeSort[T : Ordering](elems: List[T]): List[T] = elems match { | |
case Nil | _::Nil => elems | |
case that => | |
type L = List[T] | |
def merge(l1: L, l2: L, acc: L): L = l1 -> l2 match { | |
case (a::as, b::_) if a < b => merge(as, l2, a::acc) | |
case (_, b::bs) => merge(l1, bs, b::acc) | |
case (a::as, _) => merge(as, l2, a::acc) |
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
Compiled from "MyInterface.java" | |
public interface batik.MyInterface { | |
public abstract java.util.List<java.lang.String> strings(); | |
public int totalLength(); // OBSERVERA DEFAULT METHOD I INTERFACE | |
Code: | |
0: iconst_0 | |
1: istore_1 | |
2: aload_0 | |
3: invokeinterface #1, 1 // InterfaceMethod strings:()Ljava/util/List; |
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
trait WkRef[+T >: Null <: AnyRef] extends WeakReference[T @uncheckedVariance] { | |
def map[U >: Null <: AnyRef](f: T => U): WkRef[U] = if(isDefined) new WeakRef[U](f(get)) else WeakNone | |
def flatMap[U >: Null <: AnyRef](f: T => WkRef[U]) = if(isDefined) f(get) else WeakNone | |
def isDefined: Boolean | |
def foreach[U](f: T => U) = if(isDefined) f(get) | |
def filter(f: T => Boolean): WkRef[T] = if(isDefined && f(get)) this else WeakNone | |
} | |
object WkRef { | |
def apply[T >: Null <: AnyRef](t: T) = t match { | |
case null => WeakNone |
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
/** | |
* Created by arneball on 2014-06-14. | |
*/ | |
object ExtractorTest extends App with Integral.ExtraImplicits{ | |
@extract def longString(str: String) = str.length > 1 | |
@extract def cool(int: Int) = Option(int).filter{ 2 < _ }.map{ 2 * } | |
@extract def evensum[T : Integral](l: List[T]) = { | |
l.sum % implicitly[Integral[T]].fromInt(2) == 0 |
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
/** | |
* Created by arneball on 2014-05-31. | |
*/ | |
object LazyTest extends App { | |
val n = new LazyTest | |
try { | |
println(n.lazyIntInDaHouse) | |
} catch { case t: Throwable => } | |
println(n.lazyIntInDaHouse) | |
} |
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
object ToFromMap { | |
implicit def materialize[T]: ToFromMap[T] = macro impl[T] | |
def impl[T: c.WeakTypeTag](c: Context): c.Expr[ToFromMap[T]] = { | |
import c.universe._ | |
val wt = weakTypeOf[T] | |
// Gets the type parameters, eg Holder[T, J] => List(T, J) | |
val baseTypes = wt.baseClasses.head.asType.typeParams.map{ _.asType.toType } | |
// Gives a Map(T -> Int, J -> Double) if we are extracting Holder[Int, Double] | |
val myTypes = baseTypes zip wt.typeArgs toMap; |
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 ext extends StaticAnnotation { | |
def macroTransform(annottees: Any*) = macro extension.impl | |
} | |
object extension { | |
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | |
import c.universe._ | |
annottees.map{ _.tree }.head match { | |
case q"def $name[..$tp](...$params): $ret = $b" => | |
val Seq(Seq(thiz, rest @ _*), rest2 @ _*) = params |
NewerOlder