Skip to content

Instantly share code, notes, and snippets.

@stuhood
stuhood / private final vs private[this] vs private
Last active August 29, 2015 13:57
The differences between `private final` and `private[this]` seem to be that: 1) the scala compiler will inline `private final`, 2) the accessor method for the field is generated, but also marked final.
// private[this] val yo = "yo"
$ javap -c -private -classpath . BlahThis
Compiled from "blah.scala"
public class BlahThis {
private final java.lang.String yo;
public java.lang.String toString();
Code:
0: aload_0
1: getfield #14 // Field yo:Ljava/lang/String;
scala> def inf(i: Long = 0): Stream[Long] = Stream.cons(i, inf(i+1))
inf: (i: Long)Stream[Long]
scala> val iterable: Iterable[Long] = inf()
iterable: Iterable[Long] = Stream(0, ?)
scala> inf().drop(Int.MaxValue).take(10): Iterable[Long]
res3: Iterable[Long] = Stream(2147483647, ?)
implicit val timer = new MockTimer
val af = Future.sleep(10.seconds).before { Future.value("A") }
val bf = Future.sleep(10.seconds).before { Future.value("B") }
object DeadlineReached extends Exception
def selectWithin(deadline: Time)(remaining: Seq[Future[String]], valuesSoFar: Seq[String] = Seq()): Future[Seq[String]] =
if (remaining.isEmpty) {
Future.value(valuesSoFar)
} else Future.select(remaining).flatMap { s =>
val (t, nextRemaining) = s
13:26:19 00:02 [run]
pex: Constructed RequestsContext context <pex.http.RequestsContext object at 0x10939f6d0>
pex: Fetching https://science-binaries.local.twitter.com/home/third_party/python/setuptools-5.4.1.tar.gz: 384.7ms.4.1.tar.gzpex: Fetching https://science-binaries.local.twitter.com/home/third_party/python/setuptools-5.4.1.tar.gz
pex: Installing /var/folders/tc/kq93y4pd5jn6gy3pfzd2zd5h0000gn/T/tmpj7aEVc: 464.8msT/tmpygKVqf/setuptools-5.4.1.tar.gzpex: Installing /var/folders/tc/kq93y4pd5jn6gy3pfzd2zd5h0000gn/T/tmpj7aEVc
installed /Users/stuhood/src/source/.pants.d/python-setup/interpreters/CPython-2.7.8.tmp.17d9015e484940c2ab4ff4394311b7b3/setuptools-5.4.1-py2.7.eggpex: Constructed RequestsContext context <pex.http.RequestsContext object at 0x10a108b50>
pex: Fetching https://science-binaries.local.twitter.com/home/third_party/python/wheel-0.24.0.tar.gz: 562.4ms24.0.tar.gzpex: Fetching https://science-binaries.local.twitter.com/home/third_party/pyt
13:22:49 00:02 [run]
pex: Constructed RequestsContext context <pex.http.RequestsContext object at 0x10939c6d0>
pex: Fetching https://science-binaries.local.twitter.com/home/third_party/python/setuptools-5.4.1.tar.gz: 272.3ms.4.1.tar.gzpex: Fetching https://science-binaries.local.twitter.com/home/third_party/python/setuptools-5.4.1.tar.gz
pex: Installing /var/folders/tc/kq93y4pd5jn6gy3pfzd2zd5h0000gn/T/tmpxixEgI: 442.9msT/tmpX7TNDO/setuptools-5.4.1.tar.gzpex: Installing /var/folders/tc/kq93y4pd5jn6gy3pfzd2zd5h0000gn/T/tmpxixEgI
installed /Users/stuhood/src/source/.pants.d/python-setup/interpreters/CPython-2.7.8.tmp.42a3678ccc6b4e2ab395acc0de6169c1/setuptools-5.4.1-py2.7.eggpex: Constructed RequestsContext context <pex.http.RequestsContext object at 0x10a107b90>
pex: Fetching https://science-binaries.local.twitter.com/home/third_party/python/wheel-0.24.0.tar.gz: 72.9ms.24.0.tar.gzpex: Fetching https://science-binaries.local.twitter.com/home/third_party/pyt
13:24:19 00:01 [run]
Detected interpreter /usr/bin/python: CPython-2.7.5
Detected interpreter /Users/stuhood/Python/CPython-2.7.8/bin/python2.7: CPython-2.7.8pex: Found site-library: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
pex: Found site-library: /Library/Python/2.7/site-packages
pex: Found site extra: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/../../Extras/lib/python
pex: Not a tained path element: /Users/stuhood/src/source/.pants.d/python-setup/chroots/6989e2e8e3cdedc3e8301919e289f60ad3e4d013/.bootstrap
pex: Not a tained path element: /Users/stuhood/src/source/.pants.d/python-setup/chroots/6989e2e8e3cdedc3e8301919e289f60ad3e4d013
pex: Not a tained path element: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
pex: Not a tained path element: /System
PEX-INFO
__main__.py
__main__.pyc
thrift.EiXtCn
thrift.efsw5Y
thrift.s5BL82
twitter
.pants.d/python-setup/chroots/6989e2e8e3cdedc3e8301919e289f60ad3e4d013//.bootstrap/_markerlib:
__init__.py
(import '(java.io BufferedReader IOException InputStream InputStreamReader OutputStreamWriter)
'(java.net URL URLConnection URLEncoder)
'(sun.misc BASE64Encoder))
(def update-url "https://twitter.com/statuses/update.xml")
(defn creds [username password]
(.trim (.encode (BASE64Encoder.) (.getBytes (str username ":" password)))))
(defn twitter [username password text]
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
record Column {
bytes name;
bytes value;
long timestamp;
union { int, null } ttl;
}
// becomes...
record Column {