Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
.idea |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Dependencies._ | ||
|
||
ThisBuild / scalaVersion := "2.12.8" | ||
ThisBuild / version := "0.1.0-SNAPSHOT" | ||
ThisBuild / organization := "com.example" | ||
ThisBuild / organizationName := "example" | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "copying-with-shapeless", | ||
libraryDependencies ++= Seq( | ||
shapeless, | ||
scalaTest % Test | ||
)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import sbt._ | ||
|
||
object Dependencies { | ||
lazy val shapeless = "com.chuusai" %% "shapeless" % "2.3.3" | ||
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.2.7 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package example | ||
|
||
import java.time.LocalDate | ||
|
||
/* Represents the individual "pages" of our application */ | ||
|
||
case class Location(pickup: String, dropOff: String, from: LocalDate, to: LocalDate) | ||
|
||
case class Vehicle(vehicleCategory: String, automatic: Boolean, numDoors: Int) | ||
|
||
case class Driver(driverAge: Int, nationality: String) | ||
|
||
/* We will merge the all data into this one class */ | ||
|
||
case class Reservation( | ||
pickup: String, | ||
dropOff: String, | ||
from: LocalDate, | ||
to: LocalDate, | ||
vehicleCategory: String, | ||
automatic: Boolean, | ||
numDoors: Int, | ||
driverAge: Int, | ||
nationality: String | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package example | ||
|
||
import java.time.LocalDate | ||
import shapeless.{::, HNil} | ||
|
||
object Main { | ||
|
||
/* Our HList representation of the case classes */ | ||
type LocationH = String :: String :: LocalDate :: LocalDate :: HNil | ||
type VehicleH = String :: Boolean :: Int :: HNil | ||
type DriverH = Int :: String :: HNil | ||
type ReservationH = String :: String :: LocalDate :: LocalDate :: String :: Boolean :: Int :: Int :: String :: HNil | ||
|
||
def main(args: Array[String]): Unit = { | ||
val locationH: LocationH = "Malaga Airport" :: "Malaga Airport" :: LocalDate.of(2018,8,1) :: LocalDate.of(2018,8,10) :: HNil | ||
val vehicleH: VehicleH = "Economy" :: false :: 4 :: HNil | ||
val driverH: DriverH = 35 :: "British" :: HNil | ||
|
||
val reservationH: ReservationH = locationH ++ vehicleH ++ driverH | ||
|
||
reservationH match { | ||
case | ||
pickup :: | ||
dropOff :: | ||
from :: | ||
to :: | ||
vehicleCategory :: | ||
automatic :: | ||
numDoors :: | ||
driverAge :: | ||
nationality :: | ||
HNil => | ||
println(s"pickup location: $pickup") | ||
} | ||
} | ||
|
||
} |