- Anker't(6pm - 2am, closed Sunday)
- Jédermann (Jazz Bar)
- Élesztő (Large craft beer pub)
- Telep (Art Gallery / Bar only open in week)
- A38 - Bar / (Venue ON A BOAT)
- Szimpla
Loads around the Palace District
import com.google.api.ads.dfp.axis.factory.DfpServices | |
import com.google.api.ads.dfp.axis.utils.v201608.{DateTimes, StatementBuilder} | |
import com.google.api.ads.dfp.axis.v201608.{AdUnitPage, InventoryServiceInterface} | |
def run(dfpSession: DfpSession): Unit = { | |
// Construct DFP Services | |
val dfpServices = new DfpServices | |
val adUnitService: InventoryServiceInterface = dfpServices.get(dfpSession, classOf[InventoryServiceInterface]) | |
@tailrec |
import os | |
import subprocess | |
# only look in home and subdirectories | |
home_dir = os.path.expanduser('~') | |
git_repos = [root for root, dirs, _ in os.walk(home_dir) if '.git' in dirs ] | |
row_format = '{:30s} {:40s} ({})' | |
print(row_format.format('Repository', 'Branch', 'Path')) |
/****************************************** | |
* Declaring variables and using types | |
*******************************************/ | |
/* | |
We can declare variables with val - once the value has been set, it cannot be changed | |
*/ | |
val myName = "Jon" | |
myName = "Jonathan" // not valid! |
/************************************************************************************** | |
* Control structures | |
* | |
* Control structures are bits of code that determine "where" your program goes - it | |
* isn't that useful having a program that does the same thing every time you run it, | |
* you want to be able to specify conditions and checks and for it to act according to | |
* those results | |
**************************************************************************************/ | |
/* |
/********************************************************************************************** | |
* Case Classes | |
* | |
* Creating our own types (through classes and, later, traits) allows us to better model the | |
* domain we are working in. Create higher level concepts and manipulate them more intuitively | |
**********************************************************************************************/ | |
/* | |
Let's say we want to calculate the distance between two cartesian points on a regular X-Y graph. | |
We could do it like so (using pythagoras's theorum of length = (x^2 + y^2) ^ 1/2): |
/*********************************************************************************************** | |
* Traits | |
* | |
* In the same way that case classes allow us to express our ideas at a higher, more conceptual | |
* level, traits can be used to link case classes together that share some commonality. | |
**********************************************************************************************/ | |
/* | |
Sticking with our geometry domain, let's say that we want to create an app | |
that will do some basic geometry for us, we can start with some squares. |
These exercises are intended to bring together a lot of what we have covered so far in our lessons. Make sure you ask for help on the scala-school channel if you get stuck!
There will be a part-2 of these exercises that will look at expanding our domain to include Books and Music, which will explore traits and how we can use them.
Remember that there are the recap worksheets that you can use as references and cheat sheets whilst attempting the exercises.
Flying in the face of successful subscription-based services, let's start mapping out the domain of an entertainment website where people can rent items of interest, we can call it Guflix and we can start with Films.
Exercises:
Write a function called parsePhoneNumber
that takes as an argument phoneNumber: String
and returns a Option[String]
representing a phone number. Why might we want to use String
here and not Int
?
Write a better max
function that returns an Option[Int]
given an argument of type List[Int]
. How would you write this for a list of String
? How about a List[Boolean]
? Would the implementations differ in any meaninful way?
Define a case class User
that represent a user in our imaginary app. A User
should have an id
a name
and an optional email
.
Create a list of Users
- call it users
- that contains 2 User
s. Let's pretend that this is some database of users for our app.
/*** | |
* Handling errors and working with success! aka: Option | |
* | |
* Every language needs to deal with things not going to plan. | |
* Many languages - including Java - do this via exceptions. Even | |
* if your function says it returns an Int, it might just explode. | |
* | |
* Some languages - including Java ( ͡ಠ ʖ̯ ͡ಠ) - use nulls. Even | |
* if your function says it returns an Int, it might return nothing. |