Functional approach specifics

Pure functions – no side effects, nothing else than transforming input parameters into returning value. State is kept outside, it can be passed into function and returned from it.


  • First-class citizen functions
  • High order functions
  • Anonymous functions
  • Closures
  • Currying
  • Lazy evaluation

Referential transparency – function call can be replaced by its returning value

Higher-order-function – function that accepts as an input other function

Partial function application (currying) – transform function with two parameters into function with one parameter, giving the dropped parameter a some value

Functional data structures – are immutable.

Instead of exceptions -> Option, Either, Result – returning values

Laziness – evaluating parameter when it used, but not declared

Memoization – remembering some resource-consuming operation’s result, and returning for later calls (some kind of caching)

Strict functions – all parameters are evaluated before function call, non-strict functions – with lazy parameters

Recursive functions consumes a data, corecursive – produces, both need terminating condition.

Monoid – set of some type, binary operation that takes two instances of the type and returns a new instance of the type, and empty “identity” element


  • computation context for other value
  • container, with two (or three) function defined: unit (constructor) and flatMap OR unit and compose OR unit, map, join

It is always possible to transform impure function into pure one, with two side-effects, one producing the pure function input, other consumes pure function output.

Effect – an object that contains an operation that produces side-effect, it has a method that executes a side-effect

Side-effect – is actually non-functional operation


C++11, BS book extract, part II, chapter 12 + 13

Parts of a Function Declaration

  • [[noreturn]], indicating that the function will not return using the normal call/return mechanism
  • override, indicating that it must be overriding a virtual function from a base class
  • final, indicating that it cannot be overriden in a derived class

That is, a prefix auto indicates that the return type is placed after the argument list. The suffix return type is preceded by −>.
The essential use for a suffix return type comes in function template declarations in which the return type depends on the arguments. For example:
template<class T, class U> auto product(const vector<T>& x, const vector<U>& y) −> decltype(x∗y);
However, the suffix return syntax can be used for any function.

A constexpr function cannot have side effects, so writing to nonlocal objects is not possible.

If there is a possible ambiguity, an initializer_list parameter takes priority.

Unspecified Number of Arguments

  • a variadic template
  • an initializer_list as the argument type
  • Terminate the argument list with the ellipsis ( … )


Automatic Overload Resolution

  • Exact match
  • Match using promotions
  • Match using standard conversions
  • Match using user-defined conversions
  • Match using the ellipsis … in a function declaration


Overloading takes place among the members of an overload set. By default, that means the functions of a single scope; functions declared in different non-namespace scopes do not overload.


The C++ standard library provides provides one of the following guarantees for every library operation:

  • The basic guarantee for all operations: The basic invariants of all objects are maintained, and no resources, such as memory, are leaked.
  • The strong guarantee for key operations: in addition to providing the basic guarantee, either the operation succeeds, or it has no effect.
  • The nothrow guarantee for some operations: in addition to providing the basic guarantee, some operations are guaranteed not to throw an exception.


Both the basic guarantee and the strong guarantee are provided on the condition that

  • user-supplied operations (such as assignments and swap() functions) do not leave container elements in invalid states
  • user-supplied operations do not leak resources
  • destructors do not throw exceptions


double compute(double) noexcept; // may not throw an exception. It terminates unconditionally by invoking std::terminate() if exception is thrown.


The noexcept Operator – template<typename T> void my_fct(T& x) noexcept(Is_pod<T>());

The handler is invoked:

  • [1] If H is the same type as E
  • [2] If H is an unambiguous public base of E
  • [3] If H and E are pointer types and [1] or [2] holds for the types to which they refer
  • [4] If H is a reference and [1] or [2] holds for the type to which H refers


The guiding principles are:

  • Don’t throw an exception while handling an exception.
  • Don’t throw an exception that can’t be caught.


The specific rules for calling terminate() are

• When no suitable handler was found for a thrown exception
• When a noexcept function tries to exit with a throw
• When a destructor invoked during stack unwinding tries to exit with a throw
• When code invoked to propagate an exception (e.g., a copy constructor) tries to exit with a throw
• When someone tries to rethrow ( throw; ) when there is no current exception being handled
• When a destructor for a statically allocated or thread-local object tries to exit with a throw
• When an initializer for a statically allocated or thread-local object tries to exit with a throw
• When a function invoked as an atexit() function tries to exit with a throw


By default, terminate() will call abort(). If that is not acceptable, the user can provide a terminate handler function by a call std::set_terminate() from <exception>

If an exception is not caught on a thread, std::terminate() is called.


Problematic windows updates

wusa.exe /uninstall /kb:2859537
wusa.exe /uninstall /kb:2872339
wusa.exe /uninstall /kb:2882822

Book read roadmap


The little MongoDB book summary

Setup steps (for windows):
1. Download mongodb from official page.
2. Extract somewhere
3. mongod.exe – server, mongo.exe – client shell
4. Create “mongodb.config” near with mongo.exe
5. Append “mongodb.config” with line “dbpath=<any local existed path>”, here data will be stored.
6. Launch mongod.exe with “–config <path to mongodb.config>” key
7. Launch mongo.exe, and enter command db.version() to make sure all is ok.

Mongodb internal entities:

server -> databases -> collections (tables) -> document (row) -> fields (collumn)

Command “db.stats()” – self descriptive
Command “” – shows all
Command “use <db name>” – switch database
Command “db.<collection name>.insert(<JSON lines to insert>)” – inserts new document into collection

_id” field is automatically added (add manually is also possible)

Command “db.<collection name>.find()” – returns list of documents

Query selector – like SQL’s where – JSON object, in format “{<field name>: <value name>}

Command “db.<collection name>.remove()” – clears collection

Operators $lt, $lte, $gt, $gte, $ne – within selector are used to specify <, <=, >, >=, !=, in format “{<field name>: {$lt: <value name>}}”

Operator $exists checks whether some field is presented within document.
Operator $or like SQL’s “or” operator. Like (all items with field1==value1 OR field2==value2):

db.<collection name>.find( $or: [ { <field1>: <value1> }, { <field2>: <value2> } ] )
Command “db.unicorns.update( { <field1>: <var1> }, { <field2>: <var2> } )” finds first document by { <field1>: <var1> } selector and replaces it with { <field2>: <value2> } document.

Operator $set used to update only one specified field of selected document, like:
db.<collection name>.update({<field1>: <val1>}, {$set: {<field2>: <value2>}})

Operator $inc increments a field with some specified value, like:

db.<collection name>.update({<selector>}, {$inc: {<field>: <value>}})

Operator $push appends some value into specified field, in case field’s types is array, like:
db.<collection name>.update({<selector>}, {$push: {<field>: <value>}})

Upserts – in case some document is found it is updated, if not – it is added, with a third true parameter, like:
Command “db.unicorns.update( { <field1>: <var1> }, { <field2>: <var2> }, true )

Multiple updates – update’s fourth parameter should be true, like
Command “db.unicorns.update( { <field1>: <var1> }, { <field2>: <var2> }, true, true )

Find detailed

Field selection
Command “db.<collection name>.find(<selector>, <selector which fields should be shown>);

Command “db.<collection name>.find().sort({<field>: -1})” – sorts documents, 1- ascending, -1 – descending order.

Command “db.unicorns.find().limit(<number of documents>).skip(<number of documents to skip>)” – allows to skip some count of documents and set a count of returned documents

Command “db.unicorns.find(<selector>).count()” – return a number of documents selected.

It is possible to insert document into some separate field.
DBRef – pointer to another document

Crapped collections (old data are dropped)


Command “db.<collection name>.ensureIndex({<field name>: 1});” creates index
Command “db.<collection name>.dropIndex({<field name>: 1});” drops index
Command “db.<collection name>.find().explain()” – cursor’s command describes returned set.

Hello world!

Hi, All

My name is Dmitry Krinitsyn, I am software developer.

Will add some info here soon…