Note, this is a living document. If there are bits of Scala you think deserve to be called 'good' or 'bad' let me know and I'll add them to the discussion below.
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
/** | |
* Convert a dataTable string representation into a List of Maps. For example: | |
* | |
* | x | y | | |
* | 1 | a is | | |
* | 2 | b does | | |
* | |
* Becomes: | |
* | |
* List(Map(x -> 1, y -> "a is"), Map(x -> 2, y -> "b does")) |
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 UniversalSet[A] extends Set[A] { | |
def contains(key: A) = true | |
def iterator = throw new UnsupportedOperationException() | |
def +(elem: A) = this | |
def -(elem: A) = throw new UnsupportedOperationException() | |
override def toString: String = "UniversalSet" | |
} |
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 myFuture = someFuture // from a previous async op | |
val result = myFuture map { f => | |
slowOp(f) // either takes ages or doesn't complete at all | |
} | |
// then some timeout on result | |
timeout(result, fallback) | |
// question is: if fallback is used, what happens to the execution of the slowOp (does it continue and hog resources?!) |
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
# Election results | |
It's election night! Exciting! We have a feed of election results from a data supplier. They will supply us a file which will be updated throughout the night as results come in. | |
## Results format | |
The fields in the file will be separated by commas but each row will vary in length as described below. | |
A result will consist of: |
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
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "Top Secret stack", | |
"Parameters": { | |
"Name": { | |
"Description": "Name of the service", | |
"Type": "String" | |
}, |
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
print 40 |
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.util.Random | |
trait Guess | |
case object Higher extends Guess | |
case object Lower extends Guess | |
val deck = 1 to 10 | |
def shuffle(decks: Seq[Seq[Int]]): Seq[Int] = { | |
val shuffled = Random.shuffle(decks.flatten) |
If you were to draw your code flow as a graph, what would it look like?
It's a useful question I've found in discerning what a good and bad architecture looks like.
Consider, the following two cases:
1) /\
/ \
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
select | |
talk_node.nid as id, | |
talk_meta.title as title, | |
node__field_talk_description.field_talk_description_value as description, | |
speaker_meta.title as author, | |
talk_meta.created as timestamp, | |
DATE_FORMAT(FROM_UNIXTIME(talk_meta.created), '%d/%m/%y') as date | |
from | |
node as talk_node, | |
node as speaker_node, |
OlderNewer