Edited, memorised or added to reading list

on 16-Aug-2014 (Sat)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

Flashcard 149629021

Tags
#bonds #duration #finance
Question
For modified duration the common units are the percent change in price per one percentage point change in yield per year (for example yield going from 8% per year (y = 0.08) to 9% per year (y = 0.09)). This will give modified duration close to the value of [...]
Answer
Macaulay duration (and the same when rates are continuously compounded)

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

Parent (intermediate) annotation

Open it
uration the common units are the percent change in price per one percentage point change in yield per year (for example yield going from 8% per year (y = 0.08) to 9% per year (y = 0.09)). This will give modified duration close to the value of <span>Macaulay duration (and the same when rates are continuously compounded)<span><body><html>

Original toplevel document

Bond duration - Wikipedia, the free encyclopedia
average time until repayment (measured in units of time such as years) while modified duration is a price sensitivity measure when the price is treated as a function of yield, the percentage change in price with respect to yield. Units[edit] <span>For modified duration the common units are the percent change in price per one percentage point change in yield per year (for example yield going from 8% per year (y = 0.08) to 9% per year (y = 0.09)). This will give modified duration close to the value of Macaulay duration (and the same when rates are continuously compounded). Formally, modified duration is a semi-elasticity, the percent change in price for a unit change in yield, rather than an elasticity, which is a percentage change in output for a percen







#anonymous-functions #functions #scala

The following expression creates a successor function for integers:

var inc = (x:Int) => x+1

Variable inc is now a function that can be used the usual way:

var x = inc(7)-1
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Anonymous Functions
ts called function values. Scala supports first-class functions, which means you can express functions in function literal syntax, i.e., (x: Int) => x + 1, and that functions can be represented by objects, which are called function values. <span>The following expression creates a successor function for integers: var inc = (x:Int) => x+1 Variable inc is now a function that can be used the usual way: var x = inc(7)-1 It is also possible to define functions with multiple parameters as follows: var mul = (x: Int, y: Int) => x*y Variable mul is now a function that can be used the usual way: println(




#currying #functions #scala

Curried functions are defined with multiple parameter lists, as follows:

def strcat(s1: String)(s2: String) = s1 + s2

Alternatively, you can also use the following syntax to define a curried function:

def strcat(s1: String) = (s2: String) => s1 + s2
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Currying Functions
esume WritingComputer GlossaryWho is Who Scala Currying Functions Advertisements Previous Page Next Page Currying transforms a function that takes multiple parameters into a chain of functions, each taking a single parameter. <span>Curried functions are defined with multiple parameter lists, as follows: def strcat(s1: String)(s2: String) = s1 + s2 Alternatively, you can also use the following syntax to define a curried function: def strcat(s1: String) = (s2: String) => s1 + s2 Following is the syntax to call a curried function: strcat("foo")("bar") You can define more than two parameters on a curried function based on your requirement. Let




#currying #functions #scala

syntax to call a curried function:

strcat("foo")("bar")
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Currying Functions
ith multiple parameter lists, as follows: def strcat(s1: String)(s2: String) = s1 + s2 Alternatively, you can also use the following syntax to define a curried function: def strcat(s1: String) = (s2: String) => s1 + s2 Following is the <span>syntax to call a curried function: strcat("foo")("bar") You can define more than two parameters on a curried function based on your requirement. Let us take a complete example to show currying concept: object Test { def main(args: Array[St




#collections #lists #scala
lists are immutable
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Lists
Computer GlossaryWho is Who Scala Lists Advertisements Previous Page Next Page Scala Lists are quite similar to arrays which means, all the elements of a list have the same type but there are two important differences. First, <span>lists are immutable, which means elements of a list cannot be changed by assignment. Second, lists represent a linked list whereas arrays are flat. The type of a list that has elements of type T is written




#collections #lists #scala
lists represent a linked list
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Lists
Scala Lists are quite similar to arrays which means, all the elements of a list have the same type but there are two important differences. First, lists are immutable, which means elements of a list cannot be changed by assignment. Second, <span>lists represent a linked list whereas arrays are flat. The type of a list that has elements of type T is written as List[T]. For example, here are few lists defined for various data types: // List of Strings val fru




#collections #lists #scala

All lists can be defined using two fundamental building blocks, a tail Nil and ::, which is pronounced cons. Nil also represents the empty list. All the above lists can be defined as follows:

// List of Strings
val fruit = "apples" :: ("oranges" :: ("pears" :: Nil))
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Lists
t;) // List of Integers val nums: List[Int] = List(1, 2, 3, 4) // Empty List. val empty: List[Nothing] = List() // Two dimensional list val dim: List[List[Int]] = List( List(1, 0, 0), List(0, 1, 0), List(0, 0, 1) ) <span>All lists can be defined using two fundamental building blocks, a tail Nil and ::, which is pronounced cons. Nil also represents the empty list. All the above lists can be defined as follows: // List of Strings val fruit = "apples" :: ("oranges" :: ("pears" :: Nil)) // List of Integers val nums = 1 :: (2 :: (3 :: (4 :: Nil))) // Empty List. val empty = Nil // Two dimensional list val dim = (1 :: (0 :: (0 :: Nil))) :: (0 :: (1 :: (0 :: Ni




#collections #lists #scala

Concatenating Lists:

You can use either ::: operator or List.:::() method or List.concat() method to add two or more lists.

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Lists
ve code is compiled and executed, it produces the following result: C:/>scalac Test.scala C:/>scala Test Head of fruit : apples Tail of fruit : List(oranges, pears) Check if fruit is empty : false Check if nums is empty : true C:/> <span>Concatenating Lists: You can use either ::: operator or List.:::() method or List.concat() method to add two or more lists. Following is the example: object Test { def main(args: Array[String]) { val fruit1 = "apples" :: ("oranges" :: ("pears" :: Nil)) val fruit2 =




#collections #scala #sets
By default, Scala uses the immutable Set. If you want to use the mutable Set, you'll have to import scala.collection.mutable.Set class explicitly.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Sets
Set is a collection that contains no duplicate elements. There are two kinds of Sets, the immutable and the mutable. The difference between mutable and immutable objects is that when an object is immutable, the object itself can't be changed. <span>By default, Scala uses the immutable Set. If you want to use the mutable Set, you'll have to import scala.collection.mutable.Set class explicitly. If you want to use both mutable and immutable sets in the same, then you can continue to refer to the immutable Set as Set but you can refer to the mutable Set as mutable.Set. Following




#collections #scala #sets
If you want to use both mutable and immutable sets in the same, then you can continue to refer to the immutable Set as Set but you can refer to the mutable Set as mutable.Set.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Sets
and immutable objects is that when an object is immutable, the object itself can't be changed. By default, Scala uses the immutable Set. If you want to use the mutable Set, you'll have to import scala.collection.mutable.Set class explicitly. <span>If you want to use both mutable and immutable sets in the same, then you can continue to refer to the immutable Set as Set but you can refer to the mutable Set as mutable.Set. Following is the example to declare immutable Sets as follows: // Empty set of integer type var s : Set[Int] = Set() // Set of integer type var s : Set[Int] = Set(1,3,5,7) or var s =




#collections #scala #sets

Concatenating Sets:

You can use either ++ operator or Set.++() method to concatenate two or more sets,

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Sets
ove code is compiled and executed, it produces the following result: C:/>scalac Test.scala C:/>scala Test Head of fruit : apples Tail of fruit : Set(oranges, pears) Check if fruit is empty : false Check if nums is empty : true C:/> <span>Concatenating Sets: You can use either ++ operator or Set.++() method to concatenate two or more sets, but while adding sets it will remove duplicate elements. Following is the example to concatenate two sets: object Test { def main(args: Array[String]) { val fruit1 = Set("a




#collections #maps #scala
By default, Scala uses the immutable Map. If you want to use the mutable Set, you'll have to import scala.collection.mutable.Map class explicitly.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Maps
es need not be unique. Maps are also called Hash tables. There are two kinds of Maps, the immutable and the mutable. The difference between mutable and immutable objects is that when an object is immutable, the object itself can't be changed. <span>By default, Scala uses the immutable Map. If you want to use the mutable Set, you'll have to import scala.collection.mutable.Map class explicitly. If you want to use both mutable and immutable Maps in the same, then you can continue to refer to the immutable Map as Map but you can refer to the mutable set as mutable.Map. Following




#collections #maps #scala
If you want to use both mutable and immutable Maps in the same, then you can continue to refer to the immutable Map as Map but you can refer to the mutable set as mutable.Map.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Maps
and immutable objects is that when an object is immutable, the object itself can't be changed. By default, Scala uses the immutable Map. If you want to use the mutable Set, you'll have to import scala.collection.mutable.Map class explicitly. <span>If you want to use both mutable and immutable Maps in the same, then you can continue to refer to the immutable Map as Map but you can refer to the mutable set as mutable.Map. Following is the example to declare immutable Maps as follows: // Empty hash table whose keys are strings and values are integers: var A:Map[Char,Int] = Map() // A map with keys and val




#collections #maps #scala

If we want to add a key-value pair to a Map, we can use the operator + as follows:

A += ('I' -> 1)
A += ('J' -> 5)
A += ('K' -> 10)
A += ('L' -> 100)
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Maps
h keys and values. val colors = Map("red" -> "#FF0000", "azure" -> "#F0FFFF") While defining empty map, the type annotation is necessary as the system needs to assign a concrete type to variable. <span>If we want to add a key-value pair to a Map, we can use the operator + as follows: A += ('I' -> 1) A += ('J' -> 5) A += ('K' -> 10) A += ('L' -> 100) Basic Operations on Map: All operations on maps can be expressed in terms of the following three methods: MethodsDescriptionkeysThis method returns an iterable containing each key in the




#collections #maps #scala

example to declare immutable Maps as follows:

// Empty hash table whose keys are strings and values are integers:
var A:Map[Char,Int] = Map()

// A map with keys and values.
val colors = Map("red" -> "#FF0000", "azure" -> "#F0FFFF")
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Maps
rt scala.collection.mutable.Map class explicitly. If you want to use both mutable and immutable Maps in the same, then you can continue to refer to the immutable Map as Map but you can refer to the mutable set as mutable.Map. Following is the <span>example to declare immutable Maps as follows: // Empty hash table whose keys are strings and values are integers: var A:Map[Char,Int] = Map() // A map with keys and values. val colors = Map("red" -> "#FF0000", "azure" -> "#F0FFFF") While defining empty map, the type annotation is necessary as the system needs to assign a concrete type to variable. If we want to add a key-value pair to a Map, we can use the operator




#collections #maps #scala

Concatenating Maps

You can use either ++ operator or Map.++() method to concatenate two or more Maps,

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Maps
it produces the following result: C:/>scalac Test.scala C:/>scala Test Keys in colors : Set(red, azure, peru) Values in colors : MapLike(#FF0000, #F0FFFF, #CD853F) Check if colors is empty : false Check if nums is empty : true C:/> <span>Concatenating Maps You can use either ++ operator or Map.++() method to concatenate two or more Maps, but while adding Maps it will remove duplicate keys. Following is the example to concatenate two Maps: object Test { def main(args: Array[String]) { val colors1 = Map("red&




#collections #scala #tuples
Scala tuple combines a fixed number of items together so that they can be passed around as a whole.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Tuples
Scala - Files I/O Scala Useful ResourcesScala Quick GuideScala Useful Resources Selected ReadingDeveloper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Tuples Advertisements Previous Page Next Page <span>Scala tuple combines a fixed number of items together so that they can be passed around as a whole. Unlike an array or list, a tuple can hold objects with different types but they are also immutable. Here is an example of a tuple holding an integer, a string, and the console: val t = (




#collections #scala #tuples
Unlike an array or list, a tuple can hold objects with different types but they are also immutable.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Tuples
loper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Tuples Advertisements Previous Page Next Page Scala tuple combines a fixed number of items together so that they can be passed around as a whole. <span>Unlike an array or list, a tuple can hold objects with different types but they are also immutable. Here is an example of a tuple holding an integer, a string, and the console: val t = (1, "hello", Console) Which is syntactic sugar (short cut) for the following: val t = new




#collections #scala #tuples

Here is an example of a tuple holding an integer, a string, and the console:

val t = (1, "hello", Console)

Which is syntactic sugar (short cut) for the following:

val t = new Tuple3(1, "hello", Console)
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Tuples
ements Previous Page Next Page Scala tuple combines a fixed number of items together so that they can be passed around as a whole. Unlike an array or list, a tuple can hold objects with different types but they are also immutable. <span>Here is an example of a tuple holding an integer, a string, and the console: val t = (1, "hello", Console) Which is syntactic sugar (short cut) for the following: val t = new Tuple3(1, "hello", Console) The actual type of a tuple depends upon the number and of elements it contains and the types of those elements. Thus, the type of (99, "Luftballons") is Tuple2[Int, String]. Th




#collections #scala #tuples
The actual type of a tuple depends upon the number and of elements it contains and the types of those elements. Thus, the type of (99, "Luftballons") is Tuple2[Int, String]. The type of ('u', 'r', "the", 1, 4, "me") is Tuple6[Char, Char, String, Int, Int, String]
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Tuples
also immutable. Here is an example of a tuple holding an integer, a string, and the console: val t = (1, "hello", Console) Which is syntactic sugar (short cut) for the following: val t = new Tuple3(1, "hello", Console) <span>The actual type of a tuple depends upon the number and of elements it contains and the types of those elements. Thus, the type of (99, "Luftballons") is Tuple2[Int, String]. The type of ('u', 'r', "the", 1, 4, "me") is Tuple6[Char, Char, String, Int, Int, String] Tuples are of type Tuple1, Tuple2, Tuple3 and so on. There currently is an upper limit of 22 in the Scala if you need more, then you can use a collection, not a tuple. For each TupleN ty




#collections #scala #tuples
Tuples are of type Tuple1, Tuple2, Tuple3 and so on. There currently is an upper limit of 22 in the Scala if you need more, then you can use a collection, not a tuple.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Tuples
and of elements it contains and the types of those elements. Thus, the type of (99, "Luftballons") is Tuple2[Int, String]. The type of ('u', 'r', "the", 1, 4, "me") is Tuple6[Char, Char, String, Int, Int, String] <span>Tuples are of type Tuple1, Tuple2, Tuple3 and so on. There currently is an upper limit of 22 in the Scala if you need more, then you can use a collection, not a tuple. For each TupleN type, where 1 <= N <= 22, Scala defines a number of element-access methods. Given the following definition: val t = (4,3,2,1) To access elements of a tuple t, you




#collections #scala #tuples

Given the following definition:

val t = (4,3,2,1)

To access elements of a tuple t, you can use method t._1 to access the first element, t._2 to access the second, and so on. For example, the following expression computes the sum of all elements of t:

val sum = t._1 + t._2 + t._3 + t._4
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Tuples
e1, Tuple2, Tuple3 and so on. There currently is an upper limit of 22 in the Scala if you need more, then you can use a collection, not a tuple. For each TupleN type, where 1 <= N <= 22, Scala defines a number of element-access methods. <span>Given the following definition: val t = (4,3,2,1) To access elements of a tuple t, you can use method t._1 to access the first element, t._2 to access the second, and so on. For example, the following expression computes the sum of all elements of t: val sum = t._1 + t._2 + t._3 + t._4 You can use Tupel to write a method that takes a List[Double] and returns the count, the sum, and the sum of squares returned in a three-element Tuple, a Tuple3[Int, Double, Double]. The




#collections #options #scala
Scala Option[T] is a container for zero or one element of a given type.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Options
cala - Files I/O Scala Useful ResourcesScala Quick GuideScala Useful Resources Selected ReadingDeveloper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Options Advertisements Previous Page Next Page <span>Scala Option[T] is a container for zero or one element of a given type. An Option[T] can be either Some[T] or None object, which represents a missing value. For instance, the get method of Scala's Map produces Some(value) if a value corresponding to a given




#collections #options #scala
An Option[T] can be either Some[T] or None object, which represents a missing value.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Options
ources Selected ReadingDeveloper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Options Advertisements Previous Page Next Page Scala Option[T] is a container for zero or one element of a given type. <span>An Option[T] can be either Some[T] or None object, which represents a missing value. For instance, the get method of Scala's Map produces Some(value) if a value corresponding to a given key has been found, or None if the given key is not defined in the Map. The Option ty




#collections #options #scala
use getOrElse() to access a value or a default when no value is present:
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Options
produces the following result: C:/>scalac Test.scala C:/>scala Test show(capitals.get( "Japan")) : Tokyo show(capitals.get( "India")) : ? C:/> Using getOrElse() Method: Following is the example of showing how to <span>use getOrElse() to access a value or a default when no value is present: object Test { def main(args: Array[String]) { val a:Option[Int] = Some(5) val b:Option[Int] = None println("a.getOrElse(0): " + a.getOrElse(0) )




#classes #scala
in Scala we cannot have static members. Instead, Scala has singleton objects.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Classes &amp; Objects
compiled and executed, it produces the following result: C:/>scalac Test.scala C:/>scala Test Point x location : 20 Point y location : 30 Point z location : 20 C:/> Singleton objects: Scala is more object-oriented than Java because <span>in Scala we cannot have static members. Instead, Scala has singleton objects. A singleton is a class that can have only one instance, i.e., object. You create singleton using the keyword object instead of class keyword. Since you can't instantiate a singleton obje




#classes #scala
A singleton is a class that can have only one instance, i.e., object. You create singleton using the keyword object instead of class keyword.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Classes &amp; Objects
ala C:/>scala Test Point x location : 20 Point y location : 30 Point z location : 20 C:/> Singleton objects: Scala is more object-oriented than Java because in Scala we cannot have static members. Instead, Scala has singleton objects. <span>A singleton is a class that can have only one instance, i.e., object. You create singleton using the keyword object instead of class keyword. Since you can't instantiate a singleton object, you can't pass parameters to the primary constructor. You already have seen all the examples using singleton objects where you called Scal




#classes #scala
Since you can't instantiate a singleton object, you can't pass parameters to the primary constructor.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Classes &amp; Objects
nted than Java because in Scala we cannot have static members. Instead, Scala has singleton objects. A singleton is a class that can have only one instance, i.e., object. You create singleton using the keyword object instead of class keyword. <span>Since you can't instantiate a singleton object, you can't pass parameters to the primary constructor. You already have seen all the examples using singleton objects where you called Scala's main method. Following is the same example of showing singleton: import java.io._ class Point(val




#classes #scala
You already have seen all the examples using singleton objects where you called Scala's main method.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Classes &amp; Objects
singleton is a class that can have only one instance, i.e., object. You create singleton using the keyword object instead of class keyword. Since you can't instantiate a singleton object, you can't pass parameters to the primary constructor. <span>You already have seen all the examples using singleton objects where you called Scala's main method. Following is the same example of showing singleton: import java.io._ class Point(val xc: Int, val yc: Int) { var x: Int = xc var y: Int = yc def move(dx: Int, dy: Int) {




#scala #traits
A trait encapsulates method and field definitions, which can then be reused by mixing them into classes.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Traits
Scala - Files I/O Scala Useful ResourcesScala Quick GuideScala Useful Resources Selected ReadingDeveloper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Traits Advertisements Previous Page Next Page <span>A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. Unlike class inheritance, in which each class must inherit from just one superclass, a class can mix in any number of traits. Traits are used to define object types by specifying the sig




#scala #traits
Unlike class inheritance, in which each class must inherit from just one superclass, a class can mix in any number of traits.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Traits
's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Traits Advertisements Previous Page Next Page A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. <span>Unlike class inheritance, in which each class must inherit from just one superclass, a class can mix in any number of traits. Traits are used to define object types by specifying the signature of the supported methods. Scala also allows traits to be partially implemented but traits may not have constructor para




#scala #traits
traits may not have constructor parameters (also called class parameters)
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Traits
h each class must inherit from just one superclass, a class can mix in any number of traits. Traits are used to define object types by specifying the signature of the supported methods. Scala also allows traits to be partially implemented but <span>traits may not have constructor parameters. A trait definition looks just like a class definition except that it uses the keyword trait as follows: trait Equal { def isEqual(x: Any): Boolean def isNotEqual(x: Any): Boolean = !




#scala #traits
Child classes extending a trait can give implementation for the un-implemented methods.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Traits
def isEqual(x: Any): Boolean def isNotEqual(x: Any): Boolean = !isEqual(x) } This trait consists of two methods isEqual and isNotEqual. Here, we have not given any implementation for isEqual where as another method has its implementation. <span>Child classes extending a trait can give implementation for the un-implemented methods. So a trait is very similar to what we have abstract classes in Java. Below is a complete example to show the concept of traits: trait Equal { def isEqual(x: Any): Boolean def isNotEq




#scala #traits
a trait is very similar to what we have abstract classes in Java.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Traits
consists of two methods isEqual and isNotEqual. Here, we have not given any implementation for isEqual where as another method has its implementation. Child classes extending a trait can give implementation for the un-implemented methods. So <span>a trait is very similar to what we have abstract classes in Java. Below is a complete example to show the concept of traits: trait Equal { def isEqual(x: Any): Boolean def isNotEqual(x: Any): Boolean = !isEqual(x) } class Point(xc: Int, yc: Int) e




#regex #scala
val pattern = "Scala".r
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Regular Expressions
ions through Regex class available in the scala.util.matching package. Let us check an example where we will try to find out word Scala from a statement: import scala.util.matching.Regex object Test { def main(args: Array[String]) { <span>val pattern = "Scala".r val str = "Scala is Scalable and cool" println(pattern findFirstIn str) } } When the above code is compiled and executed, it produces the following result: C:/




#regex #scala
We create a String and call the r( ) method on it. Scala implicitly converts the String to a RichString and invokes that method to get an instance of Regex.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Regular Expressions
tr = "Scala is Scalable and cool" println(pattern findFirstIn str) } } When the above code is compiled and executed, it produces the following result: C:/>scalac Test.scala C:/>scala Test Some(Scala) C:/> <span>We create a String and call the r( ) method on it. Scala implicitly converts the String to a RichString and invokes that method to get an instance of Regex. To find a first match of the regular expression, simply call the findFirstIn() method. If instead of finding only the first occurrence we would like to find all occurrences of the matchi




#extractor-objects #scala
An extractor in Scala is an object that has a method called unapply as one of its members.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Extractors
a - Files I/O Scala Useful ResourcesScala Quick GuideScala Useful Resources Selected ReadingDeveloper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Extractors Advertisements Previous Page Next Page <span>An extractor in Scala is an object that has a method called unapply as one of its members. The purpose of that unapply method is to match a value and take it apart. Often, the extractor object also defines a dual method apply for building values, but this is not required. Foll




#extractor-objects #scala
The purpose of that unapply method is to match a value and take it apart.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Extractors
gDeveloper's Best PracticesEffective Resume WritingComputer GlossaryWho is Who Scala Extractors Advertisements Previous Page Next Page An extractor in Scala is an object that has a method called unapply as one of its members. <span>The purpose of that unapply method is to match a value and take it apart. Often, the extractor object also defines a dual method apply for building values, but this is not required. Following example shows an extractor object for email addresses: object Test {




#extractor-objects #scala
Often, the extractor object also defines a dual method apply for building values, but this is not required.
statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Extractors
Who Scala Extractors Advertisements Previous Page Next Page An extractor in Scala is an object that has a method called unapply as one of its members. The purpose of that unapply method is to match a value and take it apart. <span>Often, the extractor object also defines a dual method apply for building values, but this is not required. Following example shows an extractor object for email addresses: object Test { def main(args: Array[String]) { println ("Apply method : " + apply("Zara&quo




#extractor-objects #scala

// The injection method (optional)
def apply(user: String, domain: String) = { user +"@"+ domain }

// The extraction method (mandatory)
def unapply(str: String): Option[(String, String)] = {
  val parts = str split "@"
  if (parts.length == 2) { Some(parts(0), parts(1)) }
  else{ None }
}

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

Scala Extractors
ly method : " + apply("Zara", "gmail.com")); println ("Unapply method : " + unapply("Zara@gmail.com")); println ("Unapply method : " + unapply("Zara Ali")); } <span>// The injection method (optional) def apply(user: String, domain: String) = { user +"@"+ domain } // The extraction method (mandatory) def unapply(str: String): Option[(String, String)] = { val parts = str split "@" if (parts.length == 2){ Some(parts(0), parts(1)) }else{ None } } } This object defines both apply and unapply methods. The apply method has the same meaning as always: it turns Test into an object that can be applied to arguments in parentheses in th