The case modifier causes the Scala compiler to automatically generate common boilerplate code for the class. Implementing this code manually is tedious and a source of errors. The following case class definition:
case class Person(name: String, age: Int)
... will have the following code automati...
The use of null values is strongly discouraged, unless interacting with legacy Java code that expects null. Instead, Option should be used when the result of a function might either be something (Some) or nothing (None).
A try-catch block is more appropriate for error-handling, but if the function ...
There are several ways to format and get a string as a result.
The .NET way is by using String.Format or StringBuilder.AppendFormat:
open System
open System.Text
let hello = String.Format ("Hello {0}", "World")
// return a string with "Hello World"
let builder...
Unity works with hierarchies in order to keep your project organized. You can assign objects a place in the hierarchy using the editor but you can also do this through code.
Parenting
You can set an object's parent with the following methods
var other = GetOtherGameObject();
other.transform.Se...
Destructuring also gives you the ability to interpret a sequence as a map:
(def my-vec [:a 1 :b 2])
(def my-lst '("smthg else" :c 3 :d 4))
(let [[& {:keys [a b]}] my-vec
[s & {:keys [c d]} my-lst]
(+ a b c d)) ;= 10
It is useful for defining functions with named p...
In oracle, the difference (in days and/or fractions thereof) between two DATEs can be found using subtraction:
SELECT DATE '2016-03-23' - DATE '2015-12-25' AS difference FROM DUAL;
Outputs the number of days between the two dates:
DIFFERENCE
----------
89
And:
SELECT TO_DATE( '201...
The MEDIAN function since Oracle 10g is an easy to use aggregation function:
SELECT MEDIAN(SAL)
FROM EMP
It returns the median of the values
Works on DATETIME values too.
The result of MEDIAN is computed by first ordering the rows. Using N as the number of rows in the group, Oracle calcula...
Following code will release the lock. There will be no problem. Behind the scenes lock statement works as try finally
lock(locker)
{
throw new Exception();
}
More can be seen in the C# 5.0 Specification:
A lock statement of the form
lock (x) ...
where x is an expression of a referenc...
Partial application means calling a function with less arguments than it has and saving the result as another function (that waits for the rest of the arguments).
multiplyBy: Int -> Int -> Int
multiplyBy x y =
x * y
multiplyByTwo : Int -> Int -- one Int has disappeared! we ...
The function toupper will convert a string to upper case (capital letters). For example:
BEGIN {
greeting = "hello"
loud_greeting = toupper(greeting)
print loud_greeting
}
This code will output "HELLO" when run.
We create a new concurrent process by calling the spawn function. The spawn function will get as parameter a function Fun that the process will evaluate. The return value of the spawn function is the created process identifier (pid).
1> Fun = fun() -> 2+2 end.
#Fun<erl_eval.20.52032458>...
Enum classes as any other classes can have a constructor and be initialized
enum class Color(val rgb: Int) {
RED(0xFF0000),
GREEN(0x00FF00),
BLUE(0x0000FF)
}
Enum classes can also declare members (i.e. properties and functions). A semicolon (;) must be placed between the last enum object and the first member declaration.
If a member is abstract, the enum objects must implement it.
enum class Color {
RED {
override val rgb: Int = 0xFF0000
...
The routing configuration is included in your app/config/config.yml file, by default the app/config/routing.yml file.
From there you can link to your own routing configuration in a bundle
# app/config/routing.yml
app:
resource: "@AppBundle/Resources/config/routing.yml"
It migh...
The routing configuration is included in your app/config/config.yml file, by default the app/config/routing.yml file.
From there you can link to the controllers that have annotated routing configuration:
# app/config/routing.yml
app:
resource: "@AppBundle/Controller"
type: ...
A browser's debugging console can be used in order to print simple messages. This debugging or web console can be directly opened in the browser (F12 key in most browsers – see Remarks below for further information) and the log method of the console Javascript object can be invoked by typing the fol...
The size of a canvas is the area it occupies on the page and is defined by the CSS width and height properties.
canvas {
width : 1000px;
height : 1000px;
}
The canvas resolution defines the number of pixels it contains. The resolution is set by setting the canvas element width and heigh...