SFINAE stands for Substitution Failure Is Not An Error. Ill-formed code that results from substituting types (or values) to instantiate a function template or a class template is not a hard compile error, it is only treated as a deduction failure.
Deduction failures on instantiating function templa...
fn main() {
let maybe_cake = Some("Chocolate cake");
let not_cake = None;
// The unwrap method retrieves the value from the Option
// and panics if the value is None
println!("{}", maybe_cake.unwrap());
// The expect method works much like the un...
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...
Fixnum#to_s takes an optional base argument and represents the given number in that base:
2.to_s(2) # => "10"
3.to_s(2) # => "11"
3.to_s(3) # => "10"
10.to_s(16) # => "a"
If no argument is provided, then it represents the number in bas...
The Arbitrary class is for types that can be randomly generated by QuickCheck.
The minimal implementation of Arbitrary is the arbitrary method, which runs in the Gen monad to produce a random value.
Here is an instance of Arbitrary for the following datatype of non-empty lists.
import Test.QuickC...
% Define serial port with a baud rate of 115200
rate = 115200;
if ispc
s = serial('COM1', 'BaudRate',rate);
elseif ismac
% Note that on OSX the serial device is uniquely enumerated. You will
% have to look at /dev/tty.* to discover the exact signature of your
% serial device
...
Assuming you created the serial port object s as in this example, then
% Write one byte
fwrite(s, 255);
% Write one 16-bit signed integer
fwrite(s, 32767, 'int16');
% Write an array of unsigned 8-bit integers
fwrite(s,[48 49 50],'uchar');
% Close the serial port
fclose(s);
As there is currently no simple way of combining dictionaries in Swift, it can be useful to overload the + and += operators in order to add this functionality using generics.
// Combines two dictionaries together. If both dictionaries contain
// the same key, the value of the right hand side dicti...
The SQL 2008 standard defines the FETCH FIRST clause to limit the number of records returned.
SELECT Id, ProductName, UnitPrice, Package
FROM Product
ORDER BY UnitPrice DESC
FETCH FIRST 10 ROWS ONLY
This standard is only supported in recent versions of some RDMSs. Vendor-specific non-stand...
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.
...
The Objective-C runtime allows you to change the implementation of a method at runtime. This is called method swizzling and is often used to exchange the implementations of two methods. For example, if the methods foo and bar are exchanged, sending the message foo will now execute the implementation...
You can split a string into an array of parts, divided by a separator character.
NSString * yourString = @"Stack,Exchange,Network";
NSArray * yourWords = [yourString componentsSeparatedByString:@","];
// Output: @[@"Stack", @"Exchange", @"Network"...
<link rel="alternate stylesheet" href="path/to/style.css" title="yourTitle">
Some browsers allow alternate style sheets to apply if they are offered. By default they will not be applied, but usually they can be changed through the browser settings:
Firefox l...
Unlike classes, structures cannot inherit:
class MyView: NSView { } // works
struct MyInt: Int { } // error: inheritance from non-protocol type 'Int'
Structures, however, can adopt protocols:
struct Vector: Hashable { ... } // works
If a case class has exactly two values, its extractor can be used in infix notation.
case class Pair(a: String, b: String)
val p: Pair = Pair("hello", "world")
val x Pair y = p
//x: String = hello
//y: String = world
Any extractor that returns a 2-tuple can work this way....
A lot of the power of ReactJS is its ability to allow nesting of components. Take the following two components:
var React = require('react');
var createReactClass = require('create-react-class');
var CommentList = reactCreateClass({
render: function() {
return (
<div className...
It's possible to declare protocol name without methods:
@protocol Person;
use it your code (class definition, etc):
@interface World : NSObject
@property (strong, nonatomic) NSArray<id<some>> *employees;
@end
and later define protocol's method somewhere in your code:
@protocol...
It's possible to treat multiple, distinct values the same way, using |:
enum Colour {
Red,
Green,
Blue,
Cyan,
Magenta,
Yellow,
Black
}
enum ColourModel {
RGB,
CMYK
}
// let's take an example colour
let colour = Colour::Red;
let model = match ...