Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. // represents a filter function that take a collection of cabs, filters and returns the result
  2. type Filter = List[Cab] => List[Cab]
  3.  
  4. /* a simple filter to filter cabs based on source and destination, */
  5. def matchRoutes(source: Source, destination: Destination): Filter = {
  6. cabs: List[Cab] => cabs.filter(c => c.finalDestination == destination && isWithinRange(c.currentLocation, source))
  7. }
  8.  
  9. def isWithinRange(cabLoc: Location, myLoc: Location) = true
  10.  
  11. /* a simple filter to filter cabs based on service type - pool, premier, etc, */
  12. def matchClass(typName: String): Filter = {
  13. cabs: List[Cab] => cabs.filter(_.typ.equalsIgnoreCase(typName))
  14. }
  15.  
  16. /* a simple filter to filter cabs based on some kind of promotion */
  17. def matchPromotionCabs: Filter = {
  18. cabs: List[Cab] => cabs.filter(_.isOnPromotion)
  19. }
  20.  
  21. /* a long laborious process of matching the best cabs based on multitude of factors
  22. * such as driver ratings, user ratings, co-passenger ratings, traffic conditions, etc
  23. * */
  24. def matchSeats(numOfSeats: Int): Filter = {
  25. cabs: List[Cab] => cabs.filter(_.seatsAvlbl == numOfSeats)
  26. }
  27.  
  28. def matchDistanceToPickUp(here: Location, dis: Double): Filter = {
  29. cabs: List[Cab] => cabs.filter(_.distanceFromHere(here) == dis)
  30. }
  31.  
  32. def matchTimeToDrop(here: Location, time: Int): Filter = {
  33. cabs: List[Cab] => cabs.filter(_.timeToDrop(here) <= time)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement