- Convert imperative scala code to functional-style using
Future
- Refer to
Authentication.scala
for this refactoring. - You are not allowed to change the signature of
loginChores
, feel free to do whatever you want with other functions.
Refer to GeographicService.scala
. The code fetches Weather and nearby places information (both http
calls to an end-point) and merges the 2 end-points responses to produce meaningful information as JSON string.
- Part 1
- Use
Future
’sflatMap
to get the aggregate result. - Re-write the same using
for
-comprehension. - In each case strive to use minimal variables.
- Measure time taken in each case and compare the results. You may use the
time
function provided therein.
- Use
- Part 2
- Echo TCP Server echos all that is sent to it, except for
QUIT
,QUIT
causes the server to close the connection with the client.
- You can either run multiple telnet sessions (acting as clients) or run the ECHO TCP Client.
- Run Server using
> ./run.sh Server.scala
- Run Client using
> ./run.sh Client.scala
- Run Telnet session using
> telnet localhost 8080
- Note your observations.
- Run Server using
- Can we make the Echo Server serve all the clients at the non-sequentially? In other words can we make Echo Server Concurrent?
- Speed, distance and time are modelled using the following types:
Distance, DistanceUnit, Time, TimeUnit and Speed
- An end-point receives distance, distanceUnit, time and timeUnit as Strings and returns the calculated speed as JSON String.
def speed(distance: String, distanceUnit: String, time: String, timeUnit: String): String = ???
authenticate
attempts to login the user into the Application. It does so as defined below:- It first attempts to log the user using the application user name and password.
- In case
appLogin
fails, it attempts to log the user using user's Gmail Id and password. - In case
gmailLogin
fails, it attempts to log the user using user's Facebook Id and password. - In case
fbLogin
fails, it gives up and does not authenticate the user.
- Compare notes on your solutions after solving Part 1 and Part 2
- Incoming Requests to various URLs of a web-service are modelled as:
- Visits - A tuple containing Client IP and number of visits made from that IP.
import java.net.InetAddress type Visits = (InetAddress, Int)
- Request - An ADT containing the web-service URL with a list of clients that made the visits.
- Speed, distance and time are modelled using the following types:
Distance, DistanceUnit, Time, TimeUnit and Speed
- An end-point receives distance, distanceUnit, time and timeUnit as Strings and returns the calculated speed as JSON String.
def speed(distance: String, distanceUnit: String, time: String, timeUnit: String): String = ???
- Relationship between speed, distance and time is given as:
speed = distance / time
- An end-point receives distance and time as Strings and needs to return the calculated speed as JSON String.
- For Success -
speedInKmsPerHrs("100", "1.5")
returns{ 'speed' : '66.66666666666667 Kms/Hrs' }
- For Failure -
speedInKmsPerHrs("100", "1.s")
returns{ 'error' : 'Cannot Calculate' }
- For Success -
- Provide implementation for the end-point
def speedInKmsPerHrs(distanceInKms: String, timeInHrs: String)
-
What is the problem with the implementation of
findById
? -
Provide implementation for
findAnyByIds
- If an event with an Id exists, return the event corresponding to that Id, else don’t return anything. In short, it returns events for Ids that exist.println(EventRepository.findAnyByIds(1,3,5,7)) // List(Event(1,Some(Diwali),2018-11-12), Event(3,None,2019-03-20))
-
Provide implementation for
findAllByIds
- If an Id doesn’t exist, the result should beNone
else it should beSome
with a list of all the events.