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 FutureOps extends FutureOps | |
trait FutureOps { | |
def toTry[A](self: Future[A])(implicit ec: ExecutionContext): Future[Try[A]] = { | |
val p = Promise[Try[A]]() | |
self onComplete { case result => p.success(result) } | |
p.future | |
} | |
def takeFirstMatch[A](futures: Traversable[Future[A]], predicate: A => Boolean)(implicit ec:ExecutionContext): Future[Option[A]] = { | |
if(futures.nonEmpty) { | |
val promise = Promise[Option[A]]() |
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
import scala.io.Source | |
//read a file and build a concordance list of the tokens in the file | |
//there's gotta be a nicer way to do this | |
def two(fileName:String) = { | |
val chunkSize = 1024 | |
Source.fromFile(fileName).getLines() | |
// read in chunkSize lines into memory at once | |
// From: http://stackoverflow.com/questions/6751463/iterate-over-lines-in-a-file-in-parallel-scala | |
.grouped(chunkSize) |
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
// note: more efficient way to store matrix is a class that uses internal Buffer[Double] of size row * columns | |
//submatrix determination for calculating determinants of matrices | |
def submatrix[A](i : Int, j : Int, matrix : Array[Array[A]]) = { | |
//returns a new array of size n-1 with the ith index removed | |
def remove[A](index : Int, arr: Seq[A]): Seq[A] = { | |
// Note: removing the ith index from a sequence is considered highly inefficient and to be avoided whenever possible | |
arr.take(index) ++ arr.drop(index+1) | |
} |
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 org.lancegatlin | |
import scala.language.higherKinds | |
import scalaz._ | |
import Id._ | |
import std._ | |
import scalaz.effect.IO | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits._ |
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 s_mach.string.impl | |
import s_mach.string._ | |
object GridOps { | |
def grid_rowCount[T](self: Grid[T]) : Int = | |
self.size | |
def grid_columnCount[T](self: Grid[T]) : Int = |
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 s_mach.codetools.bigcaseclass | |
import s_mach.string._ | |
object BigCaseClassPrinter { | |
def print(name: String, fields: Vector[CaseClassField]) : String = { | |
val subCaseClasses = fields.grouped(CASECLASS_MAX_FIELDS).toVector | |
/* | |
_1 : Licensee.Licensee1, |
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 test { | |
trait Nullable | |
type MaybeNullBase[A >: Null] = { | |
type inner = A | |
} | |
type MaybeNull[A >: Null] = MaybeNullBase[A] with Null | |
object NotNull { | |
@inline def apply[A >: Null](a: A): MaybeNull[A] = a.asInstanceOf[MaybeNull[A]] |
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
import scala.languageFeature.higherKinds | |
trait Var[A] { | |
def isSet : Boolean | |
def :=(a: A) : Unit | |
def unset() : Unit | |
def toOption: Option[A] | |
def assumeSetAndGet : A | |
} |
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 Exec[F[_]] extends Monad[F] { | |
/** | |
Execute a block of code in in the context of F | |
F may execute code block asynchronously, synchronously or may suspend execution. | |
Note: if F suspends execution, this typeclass does not define how to execute the suspended code | |
F may capture effects or may not capture effects | |
F may catch exceptions or may not catch exceptions | |
*/ |
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
/-----------------------------------------------------------\ | |
| | | |
|-----------------------------------------------------------. | |
| Orientation = face-away | | |
| ••••• = hold key | | |
| ▒▒▒▒▒ = unassigned | | |
| ▒▒▒▒* = mouse button | | |
.-------------------. | | |
| ▒▒▒▒* ▒▒▒▒* ▒▒▒▒* | | | |
.-------------------. | |
OlderNewer