Skip to content

Commit

Permalink
Make plan.build optional
Browse files Browse the repository at this point in the history
identity creates a lambda closure that has a gibberish toString
method, making it difficult to read the Plan case object.
  • Loading branch information
isaacl committed Aug 12, 2018
1 parent 871d6b5 commit 9a59b4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions modules/tournament/src/main/Schedule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ case class Schedule(

def perfType = PerfType.byVariant(variant) | Schedule.Speed.toPerfType(speed)

def plan = Schedule.Plan(this, identity)
def plan(build: Tournament => Tournament) = Schedule.Plan(this, build)
def plan = Schedule.Plan(this, None)
def plan(build: Tournament => Tournament) = Schedule.Plan(this, build.some)

override def toString = s"$freq $variant $speed $conditions $at"
}

object Schedule {

case class Plan(schedule: Schedule, build: Tournament => Tournament)
case class Plan(schedule: Schedule, build: Option[Tournament => Tournament])

sealed abstract class Freq(val id: Int, val importance: Int) extends Ordered[Freq] {

Expand Down
2 changes: 1 addition & 1 deletion modules/tournament/src/main/TournamentApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class TournamentApi(

private[tournament] def createFromPlan(plan: Schedule.Plan): Funit = {
val minutes = Schedule durationFor plan.schedule
val tournament = plan build Tournament.schedule(plan.schedule, minutes)
val tournament = plan.build.foldRight(Tournament.schedule(plan.schedule, minutes)) { _(_) }
logger.info(s"Create $tournament")
TournamentRepo.insert(tournament).void
}
Expand Down

0 comments on commit 9a59b4b

Please sign in to comment.