Skip to content

Instantly share code, notes, and snippets.

def foldLeftViaFoldRight[A, B](l: List[A], z: B)(f: (B, A) => B): B = {
foldRight(l, (b:B) => b)((a,g) => b => g(f(b,a)))(z)
}
def foldLeft[A,B](l: List[A], z: B)(f: (B, A) => B): B
def foldRight[A, B](l: List[A], z: B)(f: (A, B) => B): B = l match {
case Nil => z
case Cons(x, xs) => f(x, foldRight(xs, z)(f))
}
Prelude Data.Char> import Data.Char
Prelude Data.Char> map Char.toUpper "hello"
<interactive>:12:5:
Failed to load interface for `Char'
It is a member of the hidden package `haskell98-2.0.0.1'.
Use -v to see a list of the files searched for.
case class AddressComponent(long_name: String, short_name: String, types: List[String])
case class Location(lat: Double, lng: Double)
case class Bounds(northeast: Location, southwest: Location)
case class Viewport(northeast: Location, southwest: Location)
case class Geometry(bounds: Bounds, location: Location, location_type: String, viewport: Viewport)
case class GeoData(geocode: GoogleGeocodeResult, elevation: GoogleApiResult[Elevation]) {
def city: Option[String] = {
if (geocode.results.isEmpty) {
None
} else if (geocode.results.head.address_components.isEmpty) {
None
} else {
geocode.results.head.address_components.find(a=> a.types.contains("neighborhood")) match {
case None => None
case Some(result) => Some(result.long_name)
case class GoogleApiResult(results: Results, status: String)
case class AddressComponent(long_name: String, short_name: String, types: List[String])
case class Location(lat: Double, lng: Double)
case class Bounds(northeast: Location, southwest:Location)
case class Viewport(northeast: Location, southwest:Location)
case class Geometry(bounds: Bounds, location: Location, locationType: String, viewport: Viewport)
case class Results(address_components: List[AddressComponent], formatted_address:String, geometry: Geometry, types: List[String])
import SprayJsonSupport._
case class GoogleApiResult[T](status: String, results: List[T])
case class AddressComponent(longName: String, shortName: String, types: List[String])
case class Location(lat: Double, lng: Double)
case class Bounds(northeast: Location, southwest:Location)
case class Viewport(northeast: Location, southwest:Location)
case class Geometry(bounds: Bounds, location: Location, locationType: String, viewport: Viewport)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val locationFormat = jsonFormat2(Location)
implicit val boundsFormat = jsonFormat2(Bounds)
{
"results": [
{
"address_components": [
{
"long_name": "11691",
"short_name": "11691",
"types": [
"postal_code"
]
[info] Starting application in the background ...
java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:274)
at scala.None$.get(Option.scala:272)
at spray.revolver.Actions$.startApp(Actions.scala:45)
at spray.revolver.Actions$.restartApp(Actions.scala:37)
at spray.revolver.RevolverPlugin$Revolver$$anonfun$settings$1$$anonfun$apply$1.apply(RevolverPlugin.scala:34)
at spray.revolver.RevolverPlugin$Revolver$$anonfun$settings$1$$anonfun$apply$1.apply(RevolverPlugin.scala:34)
at sbt.Scoped$$anonfun$hf7$1.apply(Structure.scala:583)
at sbt.Scoped$$anonfun$hf7$1.apply(Structure.scala:583)