Tutorial by Examples: ch

The where statement may be used within a switch case match to add additional criteria required for a positive match. The following example checks not only for the range, but also if the number is odd or even: switch (temperature) { case 0...49 where temperature % 2 == 0: print(&quot...
The quickCheck function tests a property on 100 random inputs. ghci> quickCheck prop_reverseDoesNotChangeLength +++ OK, passed 100 tests. If a property fails for some input, quickCheck prints out a counterexample. prop_reverseIsAlwaysEmpty xs = reverse xs == [] -- plainly not true for all ...
Ruby has many types of enumerators but the first and most simple type of enumerator to start with is each. We will print out even or odd for each number between 1 and 10 to show how each works. Basically there are two ways to pass so called blocks. A block is a piece of code being passed which will...
Pipes may be chained. <p>Today is {{ today | date:'fullDate' | uppercase}}.</p>
String data types of either fixed length or variable length. Syntax: CHAR [ ( n_chars ) ] VARCHAR [ ( n_chars ) ] Examples: SELECT CAST('ABC' AS CHAR(10)) -- 'ABC ' (padded with spaces on the right) SELECT CAST('ABC' AS VARCHAR(10)) -- 'ABC' (no padding due to variable character) SELE...
UNICODE string data types of either fixed length or variable length. Syntax: NCHAR [ ( n_chars ) ] NVARCHAR [ ( n_chars | MAX ) ] Use MAX for very long strings that may exceed 8000 characters.
In Python 3, many of the dictionary methods are quite different in behaviour from Python 2, and many were removed as well: has_key, iter* and view* are gone. Instead of d.has_key(key), which had been long deprecated, one must now use key in d. In Python 2, dictionary methods keys, values and items ...
quickCheckAll is a Template Haskell helper which finds all the definitions in the current file whose name begins with prop_ and tests them. {-# LANGUAGE TemplateHaskell #-} import Test.QuickCheck (quickCheckAll) import Data.List (sort) idempotent :: Eq a => (a -> a) -> a -> Bool ...
Switch statements compare a single test value to multiple conditions, and performs any associated actions for successful comparisons. It can result in multiple matches/actions. Given the following switch... switch($myValue) { 'First Condition' { 'First Action' } 'Second Condition' ...
The -Regex parameter allows switch statements to perform regular expression matching against conditions. Example: switch -Regex ('Condition') { 'Con\D+ion' {'One or more non-digits'} 'Conditio*$' {'Zero or more "o"'} 'C.ndition' {'Any single char.'} '^C\w+ition$'...
The break keyword can be used in switch statements to exit the statement before evaluating all conditions. Example: switch('Condition') { 'Condition' { 'First Action' } 'Condition' { 'Second Action' break } 'Condition' { 'Third Action' } } Output...
The -Wildcard parameter allows switch statements to perform wildcard matching against conditions. Example: switch -Wildcard ('Condition') { 'Condition' {'Normal match'} 'Condit*' {'Zero or more wildcard chars.'} 'C[aoc]ndit[f-l]on' {'Range and set of chars...
The -Exact parameter enforces switch statements to perform exact, case-insensitive matching against string-conditions. Example: switch -Exact ('Condition') { 'condition' {'First Action'} 'Condition' {'Second Action'} 'conditioN' {'Third Action'} '^*ondition$' {'Fourth Action...
The -CaseSensitive parameter enforces switch statements to perform exact, case-sensitive matching against conditions. Example: switch -CaseSensitive ('Condition') { 'condition' {'First Action'} 'Condition' {'Second Action'} 'conditioN' {'Third Action'} } Output: Second Act...
The -file parameter allows the switch statement to receive input from a file. Each line of the file is evaluated by the switch statement. Example file input.txt: condition test Example switch statement: switch -file input.txt { 'condition' {'First Action'} 'test' {'Second Action...
The Default keyword is used to execute an action when no other conditions match the input value. Example: switch('Condition') { 'Skip Condition' { 'First Action' } 'Skip This Condition Too' { 'Second Action' } Default { 'Default Action' } } Output: D...
It's possible to attach an object to an existing object as if there was a new property. This is called association and allows one to extend existing objects. It can be used to provide storage when adding a property via a class extension or otherwise add additional information to an existing object. ...
To search if a String contains a substring, do the following: NSString *myString = @"This is for checking substrings"; NSString *subString = @"checking"; BOOL doesContainSubstring = [myString containsString:subString]; // YES If targeting iOS 7 or OS X 10.9 (or earlier)...
It is possible to bind values to names using @: struct Badger { pub age: u8 } fn main() { // Let's create a Badger instances let badger_john = Badger { age: 8 }; // Now try to find out what John's favourite activity is, based on his age match badger_john.age { ...
// Create a boolean value let a = true; // The following expression will try and find a pattern for our value starting with // the topmost pattern. // This is an exhaustive match expression because it checks for every possible value match a { true => println!("a is true"), ...

Page 11 of 109