vb.net 2d barcode dll res10: Option[java.lang.String] = None in Font

Encode Data Matrix ECC200 in Font res10: Option[java.lang.String] = None

res10: Option[java.lang.String] = None
Data Matrix ECC200 Creation In None
Using Barcode printer for Font Control to generate, create Data Matrix 2d barcode image in Font applications.
www.OnBarcode.com
Creating QR Code JIS X 0510 In None
Using Barcode maker for Font Control to generate, create QR Code 2d barcode image in Font applications.
www.OnBarcode.com
scala> p.get(9)
PDF417 Generator In None
Using Barcode creation for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
Make Barcode In None
Using Barcode drawer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
res11: Option[java.lang.String] = Some(Elwood)
GTIN - 12 Generation In None
Using Barcode creation for Font Control to generate, create UPC Code image in Font applications.
www.OnBarcode.com
Painting Code39 In None
Using Barcode generation for Font Control to generate, create Code 39 Full ASCII image in Font applications.
www.OnBarcode.com
You can return a default value if the key is not found:
Code128 Encoder In None
Using Barcode maker for Font Control to generate, create Code-128 image in Font applications.
www.OnBarcode.com
Generating Rationalized Codabar In None
Using Barcode creation for Font Control to generate, create USS Codabar image in Font applications.
www.OnBarcode.com
scala> p.getOrElse(99, "Nobody")
Data Matrix ECC200 Printer In Java
Using Barcode maker for Java Control to generate, create Data Matrix image in Java applications.
www.OnBarcode.com
Painting ECC200 In None
Using Barcode printer for Office Excel Control to generate, create ECC200 image in Microsoft Excel applications.
www.OnBarcode.com
res55: java.lang.String = Nobody
Painting QR-Code In Java
Using Barcode creation for BIRT reports Control to generate, create QR-Code image in BIRT applications.
www.OnBarcode.com
Decode PDF417 In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
scala> p.getOrElse(1, "Nobody")
Encoding GTIN - 13 In Java
Using Barcode printer for BIRT Control to generate, create GS1 - 13 image in BIRT reports applications.
www.OnBarcode.com
Draw UPC A In Java
Using Barcode creator for Eclipse BIRT Control to generate, create GS1 - 12 image in Eclipse BIRT applications.
www.OnBarcode.com
res56: java.lang.String = David
Barcode Generator In None
Using Barcode creation for Microsoft Excel Control to generate, create Barcode image in Excel applications.
www.OnBarcode.com
Decode Barcode In Visual Studio .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
We can also use flatMap with Options to find all the values with keys between 1 and 5:
Paint 2D In VS .NET
Using Barcode generator for .NET framework Control to generate, create Matrix Barcode image in .NET applications.
www.OnBarcode.com
Encode Code 3/9 In Java
Using Barcode creator for Java Control to generate, create Code 3/9 image in Java applications.
www.OnBarcode.com
scala> 1 to 5 flatMap(p.get)
ECC200 Decoder In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Code 128 Creator In Objective-C
Using Barcode drawer for iPad Control to generate, create Code 128B image in iPad applications.
www.OnBarcode.com
res53: Seq.Projection[java.lang.String] = RangeG(David)
CHAPTER 3 COLLECTIONS AND THE JOY OF IMMUTABILITY
In this case, we create a range of numbers from 1 to 5. We flatMap this collection, passing in a function, p.get. Wait, you say, p.get isn t a function, it s a method, but you didn t include the parameter. Scala is very cool, because if it s expecting a function with parameters of a particular type and you pass a method that takes those parameters, Scala will promote the method with its missing parameters to a function. We ll explore Options in the next subsection. Let s continue exploring Map. We can remove elements from our Map:
scala> p -= 9 scala> p
res20: Map[Int,String] = Map(1 -> David, 8 -> Archer)
We can test the Map to see whether it contains a particular key:
scala> p.contains(1)
res21: Boolean = true
We can operate on the collection of keys. We get a collection of keys from our Map and use reduceLeft to find the largest key:
scala> p.keys.reduceLeft(_ max _)
res22: Int = 8
And we can use reduceLeft on the collection of values to find the largest String:
scala> p.values.reduceLeft((a, b) => if (a > b) a else b)
res23: java.lang.String = David
CHAPTER 3 COLLECTIONS AND THE JOY OF IMMUTABILITY
We can test whether any of the values contains the letter z :
scala> p.values.exists(_.contains("z"))
res28: Boolean = false
You can also add a bunch of elements to a Map using the ++ method:
scala> p ++= List(5 -> "Cat", 6 -> "Dog")
p: Map[Int,String] = Map(1 -> David, 8 -> Archer, 5 -> Cat, 6 -> Dog)
And you can remove a bunch of keys with the -- method:
scala> p --= List(8, 6)
res40: Map[Int, String] = Map(1 -> David, 5 -> Cat)
Maps are Scala collections and have collection manipulation methods. This means we can use methods including map, filter, and foldLeft. One of the tricky parts of using Java s immutable collections is iterating over the collection and simultaneously removing elements. In my code, I have to create an accumulator for the keys I m going to remove, loop over the collection, find all the keys to remove, and then iterate over the collection of keys to remove and remove them from the collection. Not only that, but I frequently forget how brittle Hashtable is and inevitably forget this sequence and get some nasty runtime errors. In Scala, it s much easier. But there s a simpler way to remove unwanted elements from a Map: def removeInvalid(in: Map[Int, Person]) = in.filter(kv => kv._2.valid)
Pretty cool, huh Map has a filter method that works just like List s filter method. The kv variable is a Pair representing the key/value pair. The filter method tests each key/ value pair by calling the function and constructs a new Map that contains only the elements that passed the filter test. Let s finish up our exploration of some of Scala s immutable data types by examining Option.
CHAPTER 3 COLLECTIONS AND THE JOY OF IMMUTABILITY
Option[T]
Option[T] provides a container for zero or one element of a given type. Option provides a very powerful alternative to Java s null. An Option[T] can be either Some[T] or None. None is an object. There is a single instance of None in your Scala program, so it s kind of like null. But None has methods on it, so you can invoke map, flatMap, filter, foreach, and so on no matter whether you have Some or None.
Let s say we have a method that retrieves a record from the database based on a primary key:
def findPerson(key: Int): Option[Person]
The method will return Some[Person] if the record is found but None if the record is not found. We can then build a method that returns the age from the primary key:
def ageFromKey(key: Int): Option[Int] = findPerson(key).map(_.age)
If the record is found in the database, ageFromKey will return Some[Int], otherwise it will return None. We can cascade mapping/flatMapping of Option without explicitly testing for None. For example, let s say we have a Map that contains parameters passed as part of a web request and a couple of helper methods. Let s make a start implementing this:
scala> import java.lang.{Boolean => JBool}
This imports java.lang.Boolean but renames it locally to JBool so it doesn t conflict with Scala s Boolean class.
scala> def tryo[T](f: => T): Option[T] = try {Some(f)} catch {case _ => None}
We define a method that wraps an operation in a try/catch block. If the operation succeeds, we wrap the result in a Some instance, otherwise return None.
scala> def toInt(s: String): Option[Int] = tryo(s.toInt) scala> def toBool(s: String) = tryo(JBool.parseBoolean(s))
We define methods that convert String to Int or Boolean. If the String can be converted, Some will be returned, otherwise None will be returned. With these helpers, we can define our method that converts from the parameters to a Person instance. This is shown in Listing 3-6.
Copyright © OnBarcode.com . All rights reserved.