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.util.Random | |
object ScalaSchool { | |
val basicClassMembers = Seq( | |
"Stuart Boundy", | |
"Diego Vazquez", | |
"Robin Edman", | |
"Matt Andrews", | |
"Shahin Kordasti", | |
"Abdul Karim", |
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 com.gu.openplatform.contentapi.backfill | |
import com.gu.openplatform.contentapi.{Parameters, Api} | |
trait BackfillQueryBuilding[F[+_]] { self: Api[F] => | |
def buildQueryFromString(queryString: String): Either[ItemQuery, SearchQuery] = { | |
val (path, parameters) = PathAndQueryString.extract(queryString) | |
val baseQuery = if (path startsWith "search") { | |
Right(search) |
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.concurrent.Future | |
object Futures { | |
def batchedTraverse[A, B](as: List[A], batchSize: Int, timeout: Int)(f: A => Future[B]) = | |
as.grouped(batchSize).foldLeft(Future.successful(List.empty[B])) { | |
case (accumulatorFuture, batch) => accumulatorFuture flatMap { accumulator => | |
Future.traverse(batch)(f) map { accumulator ++ _ } | |
} | |
} | |
} |
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 common | |
import scalaz.PLensFamily | |
object Lenses { | |
implicit class RichPLensFamily[A, B, C, D](lens: PLensFamily[A, B, C, D]) { | |
def sets(d: D) = (a: A) => lens.set(a, d) | |
def mods(f: C => D) = (a: A) => lens.mod(f, 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
val collectionGroups = collections.map(Group.fromCollection) | |
val transforms = for { | |
_ <- (Group.showHeader.partial compose listHeadPLens[Group]) %= false | |
_ <- listTailPLens[Group] %= (_.map(Group.required.set(_, false))) | |
} yield () | |
val groups = transforms(collectionGroups)._1 ++ premiumGroups |
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 groups = listTailPLens[Group].mod( | |
_.map(group => Group.required.set(group, false)), | |
collections.map(Group.fromCollection) | |
) ++ premiumGroups | |
val groups2 = listHeadPLens[Group].mod( | |
Group.showHeader.set(_, false), | |
groups | |
) |
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
var INT_MIN_VALUE = -2147483648; | |
var INT_MAX_VALUE = 2147483647; | |
var INT_RANGE = INT_MAX_VALUE - INT_MIN_VALUE; | |
function rand32BitInteger() { | |
return Math.floor(Math.random() * INT_RANGE + 1 + INT_MIN_VALUE); | |
} |
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
[info] Compiling 9 Scala sources to /home/robert/Git/mobile-apps-api/common/target/scala-2.10/classes... | |
[error] /home/robert/Git/mobile-apps-api/common/app/lib/PlayJson.scala:17: type mismatch; | |
[error] found : (play.api.libs.json.Reads[Nothing], play.api.libs.json.Reads[Nothing]) => play.api.libs.json.Reads[Nothing] | |
[error] required: (play.api.libs.json.Reads[_ <: A], play.api.libs.json.Reads[_ <: A]) => play.api.libs.json.Reads[_ <: A] | |
[error] def oneOf[A](reads: Seq[Reads[_ <: A]]): Reads[A] = reads.reduce(either) | |
[error] ^ | |
[error] /home/robert/Git/mobile-apps-api/common/app/lib/PlayJson.scala:17: type mismatch; | |
[error] found : play.api.libs.json.Reads[_$1] where type _$1 <: A | |
[error] required: play.api.libs.json.Reads[A] | |
[error] Note: _$1 <: A, but trait Reads is invariant in type 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
package lib | |
import play.api.libs.json.{Writes, JsResult, Reads} | |
object PlayJson { | |
implicit class RichWrites[A](self: Writes[A]) { | |
def orElse[AA >: A, B <: AA](other: Writes[B]): Writes[AA] = { | |
Writes[AA] { | |
case a: A => self.writes(a) | |
case b: B => other.writes(b) |
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
intervals :: Integer -> [Float] | |
intervals n = [-1.0 + (fromIntegral i) * interval | i <- [0 .. (n - 1)]] | |
where interval = 2.0 / (fromIntegral (n - 1)) | |
main = print $ intervals 10 |