Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Tags
#odersky-programming-in-scala-2ed #scala
Question
How can you simplify this code using closure to avoid passing query as an argument to filesMatching, where filesEnding is the public API client function?

def filesEnding(query: String) =
  filesMatching(query, _.endsWith(_))

def filesMatching(query: String,
    matcher: (String, String) => Boolean) = {
  for (file <- filesHere; if matcher(file.getName, query))
    yield file
}
Answer

def filesEnding(query: String) =
  filesMatching(_.endsWith(query))

def filesMatching(matcher: String => Boolean) =
  for (file <- filesHere; if matcher(file.getName))
    yield file


Tags
#odersky-programming-in-scala-2ed #scala
Question
How can you simplify this code using closure to avoid passing query as an argument to filesMatching, where filesEnding is the public API client function?

def filesEnding(query: String) =
  filesMatching(query, _.endsWith(_))

def filesMatching(query: String,
    matcher: (String, String) => Boolean) = {
  for (file <- filesHere; if matcher(file.getName, query))
    yield file
}
Answer
?

Tags
#odersky-programming-in-scala-2ed #scala
Question
How can you simplify this code using closure to avoid passing query as an argument to filesMatching, where filesEnding is the public API client function?

def filesEnding(query: String) =
  filesMatching(query, _.endsWith(_))

def filesMatching(query: String,
    matcher: (String, String) => Boolean) = {
  for (file <- filesHere; if matcher(file.getName, query))
    yield file
}
Answer

def filesEnding(query: String) =
  filesMatching(_.endsWith(query))

def filesMatching(matcher: String => Boolean) =
  for (file <- filesHere; if matcher(file.getName))
    yield file

If you want to change selection, open document below and click on "Move attachment"

pdf

cannot see any pdfs

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.