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
interface PostprocessBreadStrategy { | |
Bread postprocess(Bread bread); | |
} | |
class PostprocessingBakery2 { | |
public Bakery2(BakeBreadStrategy bakeStrategy, PostprocessingBreadStrategy postprocessStrategy) { | |
// ... | |
} |
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
interface ProduceStrategy { | |
Bread produce(Ingredients ingredients); | |
} | |
interface PostprocessStrategy { | |
Bread postprocess(Bread bread); | |
} | |
class ChainedPostprocessStrategy implements PosprocessStrategy { | |
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 FunctionalBakery { | |
public Bakery2(F<Ingredients, Bread> bakeStrategy, | |
F<Bread, Bread> postprocessStrategy) { | |
// ... | |
} | |
public void produceBread() { | |
Ingredients ingredients = prepareIngredients(); | |
Bread bread = bakeStrategy.f(ingredients); |
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 Phases { | |
public static final F<Bread, Bread> SLICE = new F<Bread, Bread>() { ... }; | |
public static final F<Bread, Bread> BOX = new F<Bread, Bread>() { ... }; | |
public static final F<Bread, Bread> SLICE_AND_BOX = SLICE.andThen(BOX); | |
} |
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 QuickAndDirty { | |
public static F<Ingredients, Bread> MAKE_BIO_BREAD = ...; | |
public static F<Ingredients, Bread> MAKE_BIO_BOXED_BREAD = | |
MAKE_BIO_BREAD.andThen(BOX); | |
} |
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 com.treetide.utils.portable.gfx | |
import scalaz.{NonEmptyList, Order} | |
trait Resolutions { | |
type Resolution = (Int, Int) | |
trait HasResolution[F] { | |
def resolution(f: F): Resolution |
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
type EitherThrowableT[F[+_], +A] = EitherT[F, Throwable, A] | |
type EitherTPromise[+A] = EitherT[Promise, Throwable, A] | |
def fetchTidied(fromUrl: String): EitherTPromise[JsoupDocument] = ... | |
def pageCount(jobs: JsoupDocument): Throwable \/ Int = ... | |
val message = for { | |
jobsPage <- fetchTidied(careersJobs) |
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
sealed trait TreeData | |
// ... | |
// could be made generic in data | |
case class Node(data: TreeData, children: List[Node]) | |
sealed trait ZipCtx | |
case object Top extends ZipCtx | |
case class At(revLeft: List[Node], right: List[Node], ctx: ZipCtx, updata: TreeData) extends ZipCtx |
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
object stateTRunner { | |
def runWhileUsing[F[+_], S, A, B](st: StateT[F, S, A])(init: S, p: S => Boolean, f: (S, A) => B)(implicit F: Monad[F]): F[List[B]] = { | |
def runWhile0(st: StateT[F, S, A], init: S, accum: List[B]): F[List[B]] = { | |
if (!p(init)) F.point(accum.reverse) | |
else F.bind(st.run(init)) { | |
case (s, a) => runWhile0(st, s, f(s, a) :: accum) | |
} | |
} | |
runWhile0(st, init, Nil) |
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
object merging { | |
// Note: Tail-recursive stream functions should always be defined on objects, not traits. | |
// see http://stackoverflow.com/questions/12486762/scala-tail-recursive-stream-processor-function-defined-in-trait-holds-reference | |
/** | |
* Merges two ordered streams. The elements can be of different | |
* types, but they need a mapping to a common type C. | |
* | |
* The mapped streams must be ordered ascending. |