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 Wrappers extends Serializable { | |
/* ********************************************************* */ | |
// Business of CleanString | |
// TODO: move this to a saner location | |
trait Wrapper[T] extends Serializable { | |
val value: T | |
} | |
trait StringWrapper extends Wrapper[String] { | |
override val value: String |
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
def isEven(x:Int) = (x % 2 == 0) | |
def isPositive(x: Int) = (x > 0) | |
def aList = List(1,2,-2,34,57, -91, -90) | |
// in this case I go from [Int] => [Bool] => Int. 2 times, because I have 2 functions. | |
val (numEven, numPos) = (aList.map(isEven).filter(_ == true).length, aList.map(isPositive).filter(_ == true).length) |
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
def prepareDiskFor(profileFileName: String): Boolean = { | |
// create directory if it doesn't exist | |
val theDir: File = Utils.getFolderFromFileName(profileFileName) | |
if (!theDir.exists() && !theDir.mkdirs()) { | |
error("Impossible to save profile because directory [%s] does not exist nor can I create it".format(theDir.getAbsolutePath)) | |
false | |
} else { | |
true | |
} | |
} |
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
val operationsFutureMat: List[Future[Try[currentype]]] = operationsFuture.map { | |
+ _.map(s => Success(s)).recover { | |
+ case x => Failure(x) |
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
def toBase36(str: String): Long = { | |
var id: Long = 0 | |
for (c <- str) { | |
val d = if (c.isDigit) c.toInt - '0'.toInt | |
else c.toInt - 'A'.toInt + 10 | |
id = (id * 36) + d | |
} | |
id | |
} | |
def fromBase36(idp: Long): String = { |
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
// define mixable traits: | |
trait T | |
trait T1 extends T | |
trait T2 extends T | |
... | |
trait T100 extends T | |
// now let's mix them: | |
trait anotherT extends T | |
// and create concrete classes. |
NewerOlder