Tutorial by Examples: f

The easiest way to consume a successful Future-- or rather, get the value inside the Future-- is to use the map method. Suppose some code calls the divide method of the FutureDivider object from the "Creating a Future" example. What would the code need to look like to get the quotient of...
Sometimes the computation in a Future can create an exception, which will cause the Future to fail. In the "Creating a Future" example, what if the calling code passed 55 and 0 to the divide method? It'd throw an ArithmeticException after trying to divide by zero, of course. How would t...
The previous examples demonstrated the individual features of a Future, handling success and failure cases. Usually, however, both features are handled much more tersely. Here's the example, written in a neater and more realistic way: object Calculator { def calculateAndReport(a: Int, b: Int...
One type of JOIN that is less known, is the FULL JOIN. (Note: FULL JOIN is not supported by MySQL as per 2016) A FULL OUTER JOIN returns all rows from the left table, and all rows from the right table. If there are rows in the left table that do not have matches in the right table, or if there a...
If your array or array-like object is numeric, that is, if all its elements are numbers, then you can use Math.min.apply or Math.max.apply by passing null as the first argument, and your array as the second. var myArray = [1, 2, 3, 4]; Math.min.apply(null, myArray); // 1 Math.max.apply(null, my...
To read default configuration properties: package com.example; public class ExampleApplication { private Properties getDefaults() throws IOException { Properties defaults = new Properties(); try (InputStream defaultsStream = ExampleApplication.class.getResou...
To find the largest or smallest element stored in a vector, you can use the methods std::max_element and std::min_element, respectively. These methods are defined in <algorithm> header. If several elements are equivalent to the greatest (smallest) element, the methods return the iterator to th...
The alert() method of the window object displays an alert box with a specified message and an OK or Cancel button. The text of that button depends on the browser and can't be modified. Syntax alert("Hello world!"); // Or, alternatively... window.alert("Hello world!"); Prod...
Prompt will display a dialog to the user requesting their input. You can provide a message that will be placed above the text field. The return value is a string representing the input provided by the user. var name = prompt("What's your name?"); console.log("Hello, " + name); ...
Transformations can be concatenated and are applied right to left Rotate a rectangle by 90 degrees and then move it down by 20 units and to the right by 20 units: <svg xmlns="http://www.w3.org/2000/svg"> <rect x="-10" y="-20" width="20" height=...
In the example below we use std::string and operator>> to read items from the file. std::ifstream file("file3.txt"); std::vector<std::string> v; std::string s; while(file >> s) // keep reading until we run out { v.push_back(s); ...
C++11 struct info_type { std::string name; int age; float height; // we define an overload of operator>> as a friend function which // gives in privileged access to private data members friend std::istream& operator>>(std::istream& is, info_...

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect x="50" y="50" height="100" width="100" stroke="black" fill="yellow"> <animateTransform a...
<svg width="900px" height="400px" viewBox="0 0 900 400"> <defs> <filter id="basicGaussian"> <feGaussianBlur stdDeviation="5"/> </filter> </defs> <image xlink:href=&q...
<svg width="900px" height="400px" viewBox="0 0 900 400"> <defs> <filter id="xAxisGaussian"> <feGaussianBlur stdDeviation="5 0"/> </filter> </defs> <image xlink:href=...
// Get the battery API navigator.getBattery().then(function(battery) { console.log( "Battery will drain in ", battery.dischargingTime, " seconds" ); });
// Get the battery API navigator.getBattery().then(function(battery) { console.log( "Battery will get fully charged in ", battery.chargingTime, " seconds" ); });
This inserts a json dictionary where one of the members is an array of strings into the table that was created in another example. INSERT INTO myjson(dict) VALUES('{"opening":"Sicilian","variations":["pelikan","dragon","najdorf"]}'); ...
In the previous example we saw how mixed data types can be inserted into a JSON field. What if we want to update that field? We are going to add scheveningen to the array named variations in the previous example. UPDATE myjson SET dict=JSON_ARRAY_APPEND(dict,'$.variations','schevening...
In Java (and other languages), using null is a common way of indicating that there is no value attached to a reference variable. In Scala, using Option is preferred over using null. Option wraps values that might be null. None is a subclass of Option wrapping a null reference. Some is a subclass of...

Page 138 of 457