Tutorial by Examples: f

typedef double (^Operation)(double first, double second); If you declare a block type as a typedef, you can then use the new type name instead of the full description of the arguments and return values. This defines Operation as a block that takes two doubles and returns a double. The type can b...
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....
The for-in loop allows you to iterate over any sequence. Iterating over a range You can iterate over both half-open and closed ranges: for i in 0..<3 { print(i) } for i in 0...2 { print(i) } // Both print: // 0 // 1 // 2 Iterating over an array or set let names = [&quo...
When you need to remove a specific value from an array, you can use the following one-liner to create a copy array without the given value: array.filter(function(val) { return val !== to_remove; }); Or if you want to change the array itself without creating a copy (for example if you write a fun...
Composer tracks which versions of packages you have installed in a file called composer.lock, which is intended to be committed to version control, so that when the project is cloned in the future, simply running composer install will download and install all the project's dependencies. Composer de...
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...
To select the children of an element you can use the children() method. <div class="parent"> <h2>A headline</h2> <p>Lorem ipsum dolor sit amet...</p> <p>Praesent quis dolor turpis...</p> </div> Change the color of all the ...
This thread-safe version of a singleton was necessary in the early versions of .NET where static initialization was not guaranteed to be thread-safe. In more modern versions of the framework a statically initialized singleton is usually preferred because it is very easy to make implementation mistak...
When assigning named methods to delegates, they will refer to the same underlying object if: They are the same instance method, on the same instance of a class They are the same static method on a class public class Greeter { public void WriteInstance() { Console.Write...
The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult. private void UseFunc(Func<string> func) { string output = func(); // Func with a single generic type parameter returns that type Console.WriteLine...
In Python 2, exec is a statement, with special syntax: exec code [in globals[, locals]]. In Python 3 exec is now a function: exec(code, [, globals[, locals]]), and the Python 2 syntax will raise a SyntaxError. As print was changed from statement into a function, a __future__ import was also added. ...
SwiftyJSON is a Swift framework built to remove the need for optional chaining in normal JSON serialization. You can download it here: https://github.com/SwiftyJSON/SwiftyJSON Without SwiftyJSON, your code would look like this to find the name of the first book in a JSON object: if let jsonObject...
In Python 2, when a property raise a error, hasattr will ignore this property, returning False. class A(object): @property def get(self): raise IOError class B(object): @property def get(self): return 'get in b' a = A() b = B() print 'a hasattr get:...
int getListOfFriends(size_t size, int friend_indexes[]) { size_t i = 0; for (; i < size; i++) { friend_indexes[i] = i; } } C99C11 /* Type "void" and VLAs ("int friend_indexes[static size]") require C99 at least. In C11 VLAs are optional. */ void getLis...
One of the things that can really boost your productivity while writing the code is effectively navigating the workspace. This also means making it comfortable for the moment. It's possible to achieve this by adjusting which areas of workspaces you see. The buttons on the top of the navigation and ...
dnf install erlang elixir
Template may accept both lvalue and rvalue references using forwarding reference: template <typename T> void f(T &&t); In this case, the real type of t will be deduced depending on the context: struct X { }; X x; f(x); // calls f<X&>(x) f(X()); // calls f<X>(...
<?php for ($i = 0; $i < 10; $i++): do_something($i); endfor; ?> <?php for ($i = 0; $i < 10; $i++): ?> <p>Do something in HTML with <?php echo $i; ?></p> <?php endfor; ?>
<?php foreach ($collection as $item): do_something($item); endforeach; ?> <?php foreach ($collection as $item): ?> <p>Do something in HTML with <?php echo $item; ?></p> <?php endforeach; ?>
<?php if ($condition): do_something(); elseif ($another_condition): do_something_else(); else: do_something_different(); endif; ?> <?php if ($condition): ?> <p>Do something in HTML</p> <?php elseif ($another_condition): ?> <p>...

Page 48 of 457