concept string in category scala

This is an excerpt from Manning's book Get Programming with Scala.
scala> def sayHello(n: String) = s"Hi $n!" sayHello: (n: String)String scala> sayHello("Scala") res1: String = Hi Scala!Figure 2.2: Analysis of the REPL’s interpretation of a function definition. The REPL identifies the function by its name, parameter, and return type.
![]()
Figure 2.2: Analysis of the REPL’s interpretation of a function definition. The REPL identifies the function by its name, parameter, and return type.
![]()
scala> List(1, 2, 3).sum res22: Int = 6 scala> List(1.4, 2.5, 3.6).sum res23: Double = 7.5 scala> List.empty[Float].sum res24: Float = 0.0 scala> List("hello", "scala").sum <console>:13: error: could not find implicit value for parameter num: Numeric[String] // The compiler could not find an implementation for Numeric[String] // since String is not a numeric type

This is an excerpt from Manning's book Functional Programming in Scala.
A function f with input type A and output type B (written in Scala as a single type: A => B, pronounced “A to B” or “A arrow B”) is a computation that relates every value a of type A to exactly one value b of type B such that b is determined solely by the value of a. Any changing state of an internal or external process is irrelevant to computing the result f(a). For example, a function intToString having type Int => String will take every integer to a corresponding string. Furthermore, if it really is a function, it will do nothing else.
Listing 2.1. A simple Scala program
// A comment! /* Another comment */ /** A documentation comment */ object MyModule { #1 def abs(n: Int): Int = #2 if (n < 0) -n #3 else n private def formatAbs(x: Int) = { #4 val msg = "The absolute value of %d is %d" #5 msg.format(x, abs(x)) #6 } def main(args: Array[String]): Unit = #7 println(formatAbs(-42)) } #1: Declares a singleton object, which simultaneously declares a class and its only instance. #2: abs takes an integer and returns an integer. #3: Returns the negation of n if it’s less than zero. #4: A private method can only be called by other members of MyModule. #5: A string with two placeholders for numbers marked as %d. #6: Replaces the two %d placeholders in the string with x and abs(x) respectively. #7: Unit serves the same purpose as void in languages like Java or C.

This is an excerpt from Manning's book Play for Scala: Covers Play 2.
To use this template, you have to render it in the hello action method to produce its HTML output. Once Play has converted the template to a Scala object called views .html.hello, this means calling its apply method. You then use the rendered template as a String value to return an Ok result:
There isn’t much code here because we cheated. We used Play’s built-in JSON library to serialize the list of numbers to its default JSON representation. Instead of formatting the numbers as a string ourselves, we used the toJson method to format the list. This formats each number as a string, and formats the list with commas and square brackets.
When you return JSON from a controller action, you pass the JsValue to the result directly. Sometimes you just want to end up with a String that contains JSON that you can send to the client. But String values are hard to manipulate, and it’s not convenient to construct JSON String instances manually, so you need another approach.
You can get the String representation using the method Json.stringify as follows:
val productJsonString = Json.stringify(product)Now productJsonString is a String with the following contents (except for the whitespace we’ve added for readability):

This is an excerpt from Manning's book Scala in Action.
My claim is that if the reverse method is invoked twice on an instance of a String, I get the same value back. The job of ScalaCheck would be to falsify this statement by generating random test data. Without going any further, let’s try a little example with ScalaCheck. Create a new directory called scalacheck and add the following build.sbt file to the root of the directory:
property("startsWith") = Prop.forAll {(x: String, y: String) => x.startsWith(y) == x.reverse.endsWith(y.reverse) }