Tutorial by Examples

We can reference a function without actually calling it by prefixing the function's name with ::. This can then be passed to a function which accepts some other function as a parameter. fun addTwo(x: Int) = x + 2 listOf(1, 2, 3, 4).map(::addTwo) # => [3, 4, 5, 6] Functions without a receiv...
Functions are declared using the fun keyword, followed by a function name and any parameters. You can also specify the return type of a function, which defaults to Unit. The body of the function is enclosed in braces {}. If the return type is other than Unit, the body must issue a return statement ...
If a function contains just one expression, we can omit the brace brackets and use an equals instead, like a variable assignment. The result of the expression is returned automatically. fun sayMyName(name: String): String = "Your name is $name"
Functions can be declared inline using the inline prefix, and in this case they act like macros in C - rather than being called, they are replaced by the function's body code at compile time. This can lead to performance benefits in some circumstances, mainly where lambdas are used as function param...
The following will run JUnit on the tests matching test/**/*Test.java. This need the junit.jar to be in the lib folder. <project name="Project" default="junit" basedir="."> <path id="classpath"> <fileset dir="lib" includ...
The following will create dist/output.jar from the source code in src and the libraries in lib, and will use src/Main.java as the main class. <project name="Project" default="main" basedir="."> <property name="src.dir" value="src&quot...
The .sort() method sorts the elements of an array. The default method will sort the array according to string Unicode code points. To sort an array numerically the .sort() method needs to have a compareFunction passed to it. Note: The .sort() method is impure. .sort() will sort the array in-place...
If you want to use the latest code, you can install it from the repository. While you potentially get new features and fixes, only numbered releases are officially supported. pip install https://github.com/pallets/flask/tarball/master
If you want to develop and contribute to the Flask project, clone the repository and install the code in development mode. git clone ssh://github.com/pallets/flask cd flask python3 -m venv env source env/bin/activate pip install -e . There are some extra dependencies and tools to be aware ...
Ajax Get: Solution 1: $.get('url.html', function(data){ $('#update-box').html(data); }); Solution 2: $.ajax({ type: 'GET', url: 'url.php', }).done(function(data){ $('#update-box').html(data); }).fail(function(jqXHR, textStatus){ alert('Error occured: ' + te...
One of the very basic animations that you could come across is the NumberAnimation. This animation works by changing the numeric value of a property of an item from an initial state to a final state. Consider the following complete example: import QtQuick 2.7 import QtQuick.Controls 2.0 ...
Django's default authentication works on username and password fields. Email authentication backend will authenticate users based on email and password. from django.contrib.auth import get_user_model class EmailBackend(object): """ Custom Email Backend to perform authent...
iex(1)> recompile Compiling 1 file (.ex) :ok
iex(1)> h List.last def last(list) Returns the last element in list or nil if list is empty. Examples ┃ iex> List.last([]) ┃ nil ┃ ┃ iex> List.last([1]) ┃ 1 ┃ ┃ iex> List.last([1, 2, 3]) ┃ 3
iex(1)> 1 + 1 2 iex(2)> v 2 iex(3)> 1 + v 3 See also: Get the value of a row with `v`
Not always the enum name is clear enough to be understood. To document an enum, use standard javadoc: /** * United States coins */ public enum Coins { /** * One-cent coin, commonly known as a penny, * is a unit of currency equaling one-hundredth * of a United Sta...
The empty-cells property determines if cells with no content should be displayed or not. This has no effect unless border-collapse is set to separate. Below an example with two tables with different values set to the empty-cells property: The table on the left has empty-cells: show while the one...
$string = "0| PHP 1| CSS 2| HTML 3| AJAX 4| JSON"; //[0-9]: Any single character in the range 0 to 9 // + : One or more of 0 to 9 $array = preg_split("/[0-9]+\|/", $string, -1, PREG_SPLIT_NO_EMPTY); //Or // [] : Character class // \d : Any digit // + : One or more ...
Dim array = New Integer() {1, 2, 3, 4} or Dim array As Int32() = {1, 2, 3, 4}
A model can provide a lot more information than just the data about an object. Let's see an example and break it down into what it is useful for: from django.db import models from django.urls import reverse from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compati...

Page 159 of 1336