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 experiments | |
object Primes { | |
class Generator[NUM](implicit numops: Integral[NUM]) { | |
import annotation.tailrec | |
import numops._ | |
private val two = one + one |
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 fr.janalyse.primes | |
import akka.actor._ | |
import ActorDSL._ | |
import akka.routing.SmallestMailboxRouter | |
import scala.collection.immutable.Queue | |
class ActorsPrimesGenerator[NUM]( | |
name: String = "DefaultPrimesGeneratorSystem", | |
startFrom: NUM = 2, |
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
def addLibraryPath(pathToAdd: String) { | |
import java.lang.reflect.Field | |
val usrPathsField: Field = classOf[ClassLoader].getDeclaredField("usr_paths") | |
usrPathsField.setAccessible(true) | |
val paths = usrPathsField.get(null).asInstanceOf[Array[String]] | |
if (!paths.contains(pathToAdd)) { | |
usrPathsField.set(null, paths :+ pathToAdd) | |
} |
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
def res2file(from: String, dest: File) { | |
import scalax.io._ | |
val in = Resource.fromInputStream(getClass().getClassLoader.getResourceAsStream(from)) | |
val output: Output = Resource.fromFile(dest) | |
output.write(in.bytes) | |
} |
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> def f(x:Int) = {println(x); x+1} | |
f: (x: Int)Int | |
scala> val bad = Stream(f(1), f(2), f(3), f(4)) | |
1 | |
2 | |
3 | |
4 | |
bad: scala.collection.immutable.Stream[Int] = Stream(2, ?) |
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> def testA:Boolean = false | |
testA: Boolean | |
scala> def testB:Boolean=true | |
testB: Boolean | |
scala> def testC:Boolean={println("oups"); false} | |
testC: Boolean | |
scala> if ((testA#::testB#::testC#::Stream.empty).exists(_ == true)) println("OK") |
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> def from1:Option[String]=None | |
from1: Option[String] | |
scala> def from2:Option[String]=Some("found") | |
from2: Option[String] | |
scala> def from3:Option[String]={println("oups"); Some("found again")} | |
from3: Option[String] | |
scala> val alts=from1#::from2#::from3#::Stream.empty |
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> if (from1.isDefined) from1 else | |
| if (from2.isDefined) from2 else | |
| if (from3.isDefined) from3 else | |
| Some("Default Value") | |
res5: Option[String] = Some(found) | |
scala> from1 match { | |
| case x if x.isDefined => x | |
| case _ => | |
| from2 match { |
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 ActorsPrimesGenerator[NUM]( | |
handler: CheckedValue[NUM] => Unit = ActorsPrimesGenerator.mkPrintHandler[NUM](), | |
name: String = "DefaultActordBasedPrimesGeneratorSystem", | |
startFrom: NUM = 2, | |
primeNth: NUM = 1, | |
notPrimeNth: NUM = 1)(implicit numops: Integral[NUM]) extends PrimesDefinitions[NUM] with Shutdownable { | |
import numops._ | |
/* | |
* To minimize the amount of messages used for back pressure regulation |
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 StreamBasedPrimesGenerator[NUM]( | |
handler: CheckedValue[NUM] => Unit = StreamBasedPrimesGenerator.defaultHandlerFactory[NUM](), | |
name: String = "DefaultStreamBasedPrimesGeneratorSystem", | |
startFrom: NUM = 2, | |
primeNth: NUM = 1, | |
notPrimeNth: NUM = 1)(implicit numops: Integral[NUM]) extends PrimesDefinitions[NUM] with Shutdownable { | |
import numops._ | |
implicit val system = ActorSystem(name) | |
import system.dispatcher |
OlderNewer