Created
July 29, 2010 15:29
-
-
Save rajeshpv/498423 to your computer and use it in GitHub Desktop.
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
Task(typeTask:String, id:Int, parentProject:Int price:Float) | |
notice "p" means project | |
task for "t" | |
there can be n number of tasks below project | |
and parent of project id will be always zero | |
the list is ordered based on id field | |
List( | |
new Task("p", 1, 0, 0.0), | |
new Task("t", 10, 1, 1.1), | |
new Task("t", 11, 1, 1.1), | |
new Task("p", 20, 0, 0.0), | |
new Task("t", 21, 2, 2.1), | |
new Task("t", 22, 2, 2.1), | |
new Task("t", 23, 2, 2.1) | |
) | |
I want to add up the price of tasks into Projects' price | |
so output should be | |
notice "2.2" value change in first item | |
and 6.3 change in 4th item | |
List( | |
new Task("p", 1, 0, 2.2), | |
new Task("t", 10, 1, 1.1), | |
new Task("t", 11, 1, 1.1), | |
new Task("p", 20, 0, 6.3), | |
new Task("t", 21, 2, 2.1), | |
new Task("t", 22, 2, 2.1), | |
new Task("t", 23, 2, 2.1) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sealed trait Task {
def id: Int
def price: Float
}
case class SimpleTask(id: Int, price: Float) extends Task
case class ProjectTask(id: Int, subTasks: List[Task]) extends Task {
def price: Float = subTasks.reduceLeft(_.price + _.price)
}