Skip to content

Commit

Permalink
Refactoring using for comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierguihot committed Jan 15, 2018
1 parent a62fda6 commit 194067e
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 434 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Overview


Version: 1.1.2
Version: 1.1.3

API Scaladoc: [GeoBase](http://xavierguihot.com/geobase/#com.geobase.GeoBase)

Expand Down Expand Up @@ -46,19 +46,19 @@ import com.geobase.GeoBase

val geoBase = new GeoBase()

assert(geoBase.getCityFor("CDG").get == "PAR")
assert(geoBase.getCountryFor("CDG").get == "FR")
assert(geoBase.getCountryForAirline("AF").get == "FR")
assert(geoBase.getCurrencyFor("NYC").get == "USD")
assert(geoBase.getDistanceBetween("PAR", "NCE").get == 686)
assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "CDG", "20160606_1757", "JFK").get == 7.5d)
assert(geoBase.getNearbyAirports("CDG", 50).get == List("LBG", "ORY", "VIY", "POX"))
assert(geoBase.getCityFor("CDG") == Success("PAR"))
assert(geoBase.getCountryFor("CDG") == Success("FR"))
assert(geoBase.getCountryForAirline("AF") == Success("FR"))
assert(geoBase.getCurrencyFor("NYC") == Success("USD"))
assert(geoBase.getDistanceBetween("PAR", "NCE") == Success(686))
assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "CDG", "20160606_1757", "JFK") == Success(7.5d))
assert(geoBase.getNearbyAirports("CDG", 50) == Success(List("LBG", "ORY", "VIY", "POX")))
```

Getters all have a return type embedded within the Try monade. Throwing
exceptions when one might request mappings for non existing locations, isn't
realy the idiomatic of scala, and simply embedding the result in the Option
monad doesn't give the user the possibility to understand what went wrong.
realy the idiomatic scala way, and simply embedding the result in the Option
monade doesn't give the user the possibility to understand what went wrong.
Thus the usage of the Try monade.


Expand All @@ -70,7 +70,7 @@ With sbt, add these lines to your build.sbt:
```scala
resolvers += "jitpack" at "https://jitpack.io"

libraryDependencies += "com.github.xavierguihot" % "geobase" % "v1.1.2"
libraryDependencies += "com.github.xavierguihot" % "geobase" % "v1.1.3"
```

With maven, add these lines to your pom.xml:
Expand All @@ -86,7 +86,7 @@ With maven, add these lines to your pom.xml:
<dependency>
<groupId>com.github.xavierguihot</groupId>
<artifactId>geobase</artifactId>
<version>v1.1.2</version>
<version>v1.1.3</version>
</dependency>
```

Expand All @@ -100,7 +100,7 @@ allprojects {
}
dependencies {
compile 'com.github.xavierguihot:geobase:v1.1.2'
compile 'com.github.xavierguihot:geobase:v1.1.3'
}
```

Expand Down
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "geobase"

version := "1.1.2"
version := "1.1.3"

scalaVersion := "2.11.8"

Expand All @@ -15,4 +15,6 @@ assemblyJarName in assembly := name.value + "-" + version.value + ".jar"

assemblyOutputPath in assembly := file("./" + name.value + "-" + version.value + ".jar")

libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.1"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
104 changes: 40 additions & 64 deletions docs/com/geobase/GeoBase.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/com/geobase/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ <h4 class="signature">

<span class="kw">val</span> geoBase = <span class="kw">new</span> GeoBase()

assert(geoBase.getCityFor(<span class="lit">"CDG"</span>).get == <span class="lit">"PAR"</span>)
assert(geoBase.getCountry(<span class="lit">"CDG"</span>).get == <span class="lit">"FR"</span>)
assert(geoBase.getCurrencyFor(<span class="lit">"NYC"</span>).get == <span class="lit">"USD"</span>)
assert(geoBase.getCountryForAirline(<span class="lit">"AF"</span>).get == <span class="lit">"FR"</span>)
assert(geoBase.getDistanceBetween(<span class="lit">"PAR"</span>, <span class="lit">"NCE"</span>).get == <span class="num">686</span>)
assert(geoBase.getTripDurationFromLocalDates(<span class="lit">"20160606_1627"</span>, <span class="lit">"CDG"</span>, <span class="lit">"20160606_1757"</span>, <span class="lit">"JFK"</span>).get == <span class="num">7.5</span>d)
assert(geoBase.getNearbyAirports(<span class="lit">"CDG"</span>, <span class="num">50</span>).get == <span class="std">List</span>(<span class="lit">"LBG"</span>, <span class="lit">"ORY"</span>, <span class="lit">"VIY"</span>, <span class="lit">"POX"</span>))</pre><p>The GeoBase object can be used within Spark jobs (in this case, don't forget
assert(geoBase.getCityFor(<span class="lit">"CDG"</span>) == Success(<span class="lit">"PAR"</span>))
assert(geoBase.getCountry(<span class="lit">"CDG"</span>) == Success(<span class="lit">"FR"</span>))
assert(geoBase.getCurrencyFor(<span class="lit">"NYC"</span>) == Success(<span class="lit">"USD"</span>))
assert(geoBase.getCountryForAirline(<span class="lit">"AF"</span>) == Success(<span class="lit">"FR"</span>))
assert(geoBase.getDistanceBetween(<span class="lit">"PAR"</span>, <span class="lit">"NCE"</span>) == Success(<span class="num">686</span>))
assert(geoBase.getTripDurationFromLocalDates(<span class="lit">"20160606_1627"</span>, <span class="lit">"CDG"</span>, <span class="lit">"20160606_1757"</span>, <span class="lit">"JFK"</span>) == Success(<span class="num">7.5</span>d))
assert(geoBase.getNearbyAirports(<span class="lit">"CDG"</span>, <span class="num">50</span>) == Success(<span class="std">List</span>(<span class="lit">"LBG"</span>, <span class="lit">"ORY"</span>, <span class="lit">"VIY"</span>, <span class="lit">"POX"</span>)))</pre><p>The GeoBase object can be used within Spark jobs (in this case, don't forget
the possibility to <b>broadcast GeoBase</b>).</p><p>Opentraveldata is an accurate and maintained source of various travel
mappings. This scala wrapper around opentraveldata mostly uses this
file: <a href="https://github.com/opentraveldata/opentraveldata/tree/master/opentraveldata/optd_por_public.csv">
Expand Down
9 changes: 5 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.2")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1")
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.2")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1")
Loading

0 comments on commit 194067e

Please sign in to comment.