Tutorial by Examples: f

#include <iostream> #include <functional> using std::placeholders::_1; // to be used in std::bind example int stdf_foobar (int x, std::function<int(int)> moo) { return x + moo(x); // std::function moo called } int foo (int x) { return 2+x; } int foo_2 (int x, in...
One of the simplest ways to control program flow is by using if selection statements. Whether a block of code is to be executed or not to be executed can be decided by this statement. The syntax for if selection statement in C could be as follows: if(cond) { statement(s); /*to be executed, o...
While if performs an action only when its condition evaluate to true, if / else allows you to specify the different actions when the condition true and when the condition is false. Example: if (a > 1) puts("a is larger than 1"); else puts("a is not larger than 1"...
When an HTTP server receives a well-formed HTTP request, it must process the information that request contains and return a response to the client. A simple HTTP 1.1 response, may look like any of the following, usually followed by a number of header fields, and possibly a response body: HTTP/1.1 2...
A common problem is having a collection of items that all need to meet a certain criteria. In the example below we have collected two items for a diet plan and we want to check that the diet doesn't contain any unhealthy food. // First we create a collection $diet = collect([ ['name' => ...
You will often find yourself with a collection of data where you are only interested in parts of the data. In the example below we got a list of participants at an event and we want to provide a the tour guide with a simple list of names. // First we collect the participants $participants = colle...
Collections also provide you with an easy way to do simple statistical calculations. $books = [ ['title' => 'The Pragmatic Programmer', 'price' => 20], ['title' => 'Continuous Delivery', 'price' => 30], ['title' => 'The Clean Coder', 'price' => 10], ] $min = col...
use-fixtures allows to wrap each deftest in namespace with code that runs before and after test. It can be used for fixtures or stubbing. Fixtures are just functions that take test function and run it with other necessary steps (before/after, wrap). (ns myapp.test (require [clojure.test :refer ...
The text-transform property allows you to change the capitalization of text. Valid values are: uppercase, capitalize, lowercase, initial, inherit, and none CSS: .example1 { text-transform: uppercase; } .example2 { text-transform: capitalize; } .example3 { text-transform: lowerc...
Functions are defined with five components: The header, which includes the defn keyword, the name of the function. (defn welcome ....) An optional Docstring that explains and document what the function does. (defn welcome "Return a welcome message to the world" ...) Pa...
Simple recursion Using recursion and the ternary conditional operator, we can create an alternative implementation of the built-in factorial function: myfactorial(n) = n == 0 ? 1 : n * myfactorial(n - 1) Usage: julia> myfactorial(10) 3628800 Working with trees Recursive functions are o...
A long-form syntax is available for defining multi-line functions. This can be useful when we use imperative structures such as loops. The expression in tail position is returned. For instance, the below function uses a for loop to compute the factorial of some integer n: function myfactorial(n) ...
Functions are objects in Julia. Like any other objects, they can be passed as arguments to other functions. Functions that accept functions are known as higher-order functions. For instance, we can implement an equivalent of the standard library's foreach function by taking a function f as the firs...
Arrow syntax Anonymous functions can be created using the -> syntax. This is useful for passing functions to higher-order functions, such as the map function. The below function computes the square of each number in an array A. squareall(A) = map(x -> x ^ 2, A) An example of using this fu...
In Vue.js, every component instance has its own isolated scope, which means that if a parent component has a child component - the child component has its own isolated scope and the parent component has its own isolated scope. For any medium to large size app, following best practices conventions p...
Deferred function calls serve a similar purpose to things like finally blocks in languages like Java: they ensure that some function will be executed when the outer function returns, regardless of if an error occurred or which return statement was hit in cases with multiple returns. This is useful f...
The following design pattern is categorized as a creational pattern. An abstract factory is used to provide an interface for creating families of related objects, without specifying concrete classes and can be used to hide platform specific classes. interface Tool { void use(); } interf...
Not always we have liberty to read from or write to a local system path. For example if R code streaming map-reduce must need to read and write to file connection. There can be other scenarios as well where one is going beyond local system and with advent of cloud and big data, this is becoming incr...
std::function can cause significant overhead. Because std::function has [value semantics][1], it must copy or move the given callable into itself. But since it can take callables of an arbitrary type, it will frequently have to allocate memory dynamically to do this. Some function implementations h...
Copy F5 Move F6 Safe delete Windows / Linux: Alt + Delete OS X / macOS: Cmd + Delete Note that the Delete key on OS X / macOS is the equivalent of the Backspace key on other operating systems. Rename Shift+ F6 Extract Method Windows / Linux: Ctrl + Alt + M OS X / macOS: Cmd + Option + M ...

Page 129 of 457