Tutorial by Examples

def quatNorm = { a, b, c, d -> Math.sqrt(a*a + b*b + c*c + d*d) } assert quatNorm(1, 4, 4, -4) == 7.0 def complexNorm = quatNorm.ncurry(1, 0, 0) // b, c == 0 assert complexNorm(3, 4) == 5.0
def noParam = { "I have $it" } def noParamCurry = noParam.curry(2) assert noParamCurry() == 'I have 2'
def honestlyNoParam = { -> "I Don't have it" } // The following all throw IllegalArgumentException honestlyNoParam.curry('whatever') honestlyNoParam.rcurry('whatever') honestlyNoParam.ncurry(0, 'whatever')
The volatile modifier is used in multi threaded programming. If you declare a field as volatile it is a signal to threads that they must read the most recent value, not a locally cached one. Furthermore, volatile reads and writes are guaranteed to be atomic (access to a non-volatile long or double i...
This example shows how to establish a connection to an SSL-enabled POP3 email server and send a simple (text only) email. // Configure mail provider Properties props = new Properties(); props.put("mail.smtp.host", "smtp.mymailprovider.com"); props.put("ma...
Because generating documentation is based on markdown, you have to do 2 things : 1/ Write your doctest and make your doctest examples clear to improve readability (It is better to give a headline, like "examples" or "tests"). When you write your tests, do not forget to give 4 s...
Once you've installed the .NET CLI tools, you can create a new project with the following command: dotnet new --lang f# This creates a command line program.

Sum

How to get the summation of amount? See the below aggregate query. > db.transactions.aggregate( [ { $group : { _id : '$cr_dr', count : {$sum : 1}, //counts the number totalAmount : {$sum : '$amount'} //sum...
How to get the average amount of debit and credit transactions? > db.transactions.aggregate( [ { $group : { _id : '$cr_dr', // group by type of transaction (debit or credit) count : {$sum : 1}, // number of transaction for each type...
Specifies a numeric minimum and maximum range for a property using System.ComponentModel.DataAnnotations; public partial class Enrollment { public int EnrollmentID { get; set; } [Range(0, 4)] public Nullable<decimal> Grade { get; set; } } If we try to insert/upd...
Specifies how the database generates values for the property. There are three possible values: None specifies that the values are not generated by the database. Identity specifies that the column is an identity column, which is typically used for integer primary keys. Computed specifies that th...
By Code-First convention, Entity Framework creates a column for every public property that is of a supported data type and has both a getter and a setter. [NotMapped] annotation must be applied to any properties that we do NOT want a column in a database table for. An example of a property that we ...
[Table("People")] public class Person { public int PersonID { get; set; } public string PersonName { get; set; } } Tells Entity Framework to use a specific table name instead of generating one (i.e. Person or Persons) We can also specify a schema for the table using [T...
public class Person { public int PersonID { get; set; } [Column("NameOfPerson")] public string PersonName { get; set; } } Tells Entity Framework to use a specific column name instead using the name of the property. You can also specify the database data type a...
public class Person { public int PersonID { get; set; } public string PersonName { get; set; } [Index] public int Age { get; set; } } Creates a database index for a column or set of columns. [Index("IX_Person_Age")] public int Age { get; set; } This creates ...
To find active ScriptableObjects during runtime, you can use Resources.FindObjectsOfTypeAll(). T[] instances = Resources.FindObjectsOfTypeAll<T>(); Where T is the type of the ScriptableObject instance you're searching. Active means it has been loaded in memory in some form before. This me...
A shallow copy is a copy of a collection without performing a copy of its elements. >>> import copy >>> c = [[1,2]] >>> d = copy.copy(c) >>> c is d False >>> c[0] is d[0] True
If you have nested lists, it is desireable to clone the nested lists as well. This action is called deep copy. >>> import copy >>> c = [[1,2]] >>> d = copy.deepcopy(c) >>> c is d False >>> c[0] is d[0] False
You can create shallow copies of lists using slices. >>> l1 = [1,2,3] >>> l2 = l1[:] # Perform the shallow copy. >>> l2 [1,2,3] >>> l1 is l2 False
A dictionary object has the method copy. It performs a shallow copy of the dictionary. >>> d1 = {1:[]} >>> d2 = d1.copy() >>> d1 is d2 False >>> d1[1] is d2[1] True

Page 593 of 1336