Tutorial by Examples: am

// Java: IntStream.range(1, 4) .mapToObj(i -> "a" + i) .forEach(System.out::println); // a1 // a2 // a3 // Kotlin: (inclusive range) (1..3).map { "a$it" }.forEach(::println)
// Java: Stream.of(1.0, 2.0, 3.0) .mapToInt(Double::intValue) .mapToObj(i -> "a" + i) .forEach(System.out::println); // a1 // a2 // a3 // Kotlin: sequenceOf(1.0, 2.0, 3.0).map(Double::toInt).map { "a$it" }.forEach(::println)
// Java: List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1"); myList.stream() .filter(s -> s.startsWith("c")) .map(String::toUpperCase) .sorted() .forEach(System.out::println); // C1 ...
// Java: Arrays.asList("a1", "a2", "a3") .stream() .findFirst() .ifPresent(System.out::println); // Kotlin: listOf("a1", "a2", "a3").firstOrNull()?.apply(::println) or, create an extension function on String calle...
// Java: String phrase = persons .stream() .filter(p -> p.age >= 18) .map(p -> p.name) .collect(Collectors.joining(" and ", "In Germany ", " are of legal age.")); System.out.println(phrase); // In Germany Max and Peter a...
// Java: Map<Integer, String> map = persons .stream() .collect(Collectors.toMap( p -> p.age, p -> p.name, (name1, name2) -> name1 + ";" + name2)); System.out.println(map); // {18=Max, 23=Peter;Pamela, ...
// Java (verbose): Collector<Person, StringJoiner, String> personNameCollector = Collector.of( () -> new StringJoiner(" | "), // supplier (j, p) -> j.add(p.name.toUpperCase()), // accumulator (j1, j2) -> j1.merge(j2), // c...
// Java: IntSummaryStatistics ageSummary = persons.stream() .collect(Collectors.summarizingInt(p -> p.age)); System.out.println(ageSummary); // IntSummaryStatistics{count=4, sum=76, min=12, average=19.000000, max=23} // Kotlin: // something to hold the stats... da...
Graph queries can be defined inline if you don't want to use an Alert variable. template graph.template { subject = ... body = `{{template "header" .}} <strong>Graph With Inline Query</strong> <div>{{.Graph "q(\"avg:300s-avg:os.mem.perce...
Scollector binaries for Windows, Mac, and Linux are available from the Bosun release page and can be saved to /opt/scollector/ or C:\Program Files\scollector\. The Scollector configuration file uses TOML v0.2.0 to specify various settings and defaults to being named scollector.toml in the same folde...
#Example of a PowerShell external collector. See http://bosun.org/scollector/external-collectors for details #This file should be saved in C:\Program Files\scollector\collectors\0\mymetrics.ps1 since it is a continuous output script #scollector.toml should have ColDir = 'C:\Program Files\scollecto...
SQL Server 2008 WITH XMLNAMESPACES ( DEFAULT 'http://www.w3.org/2000/svg', 'http://www.w3.org/1999/xlink' AS xlink ) SELECT 'example.jpg' AS 'image/@xlink:href', '50px' AS 'image/@width', '50px' AS 'image/@height' FOR XML PATH('svg') <svg xmlns:xlink="http:...
You can use a relative path to link to pages on the same website. <a href="/example">Text Here</a> The above example would go to the file example at the root directory (/) of the server. If this link was on http://example.com, the following two links would bring the user...
A lambda expression evaluated in a class' member function is implicitly a friend of that class: class Foo { private: int i; public: Foo(int val) : i(val) {} // definition of a member function void Test() { auto lamb = [](Foo &foo, int val) ...
Some regular expression flavors allow named capture groups. Instead of by a numerical index you can refer to these groups by name in subsequent code, i.e. in backreferences, in the replace pattern as well as in the following lines of the program. Numerical indexes change as the number or arrangemen...
You define a map using the keyword map, followed by the types of its keys and its values: // Keys are ints, values are ints. var m1 map[int]int // initialized to nil // Keys are strings, values are ints. var m2 map[string]int // initialized to nil Maps are reference types, and once defined ...
One can declare and initialize a map in a single statement using a composite literal. Using automatic type Short variable declaration: mapIntInt := map[int]int{10: 100, 20: 100, 30: 1000} mapIntString := map[int]string{10: "foo", 20: "bar", 30: "baz"} mapStringInt :...
The zero value of a map is nil and has a length of 0. var m map[string]string fmt.Println(m == nil) // true fmt.Println(len(m) ==0) // true A nil map has no keys nor can keys be added. A nil map behaves like an empty map if read from but causes a runtime panic if written to. var m map[string]...
import fmt people := map[string]int{ "john": 30, "jane": 29, "mark": 11, } for key, value := range people { fmt.Println("Name:", key, "Age:", value) } Note that when iterating over a map with a range loop, the iteration order i...
people := map[string]int{ "john": 30, "jane": 29, "mark": 11, } for key, _ := range people { fmt.Println("Name:", key) } If you are just looking for the keys, since they are the first value, you can simply drop the underscore: for key := r...

Page 8 of 129