def honestlyNoParam = { ->
"I Don't have it"
}
// The following all throw IllegalArgumentException
honestlyNoParam.curry('whatever')
honestlyNoParam.rcurry('whatever')
honestlyNoParam.ncurry(0, 'whatever')
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.
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 ...
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
In functional programming languages like F# null values are considered
potentially harmful and poor style (non-idiomatic).
Consider this C# code:
string x = SomeFunction ();
int l = x.Length;
x.Length will throw if x is null let's add protection:
string x = SomeFunction ();
int l = x ...
Error handling is important but can make an elegant algorithm into a mess.
Railway Oriented Programming (ROP)
is used to make error handling elegant and composable.
Consider the simple function f:
let tryParse s =
let b, v = System.Int32.TryParse s
if b then Some v else None
let f (g : ...