Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* Adator. prog.
  + feladatsor
  + quick link

Teaching

* Prog. for Data Sci.
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

fold()

See also https://dlang.org/phobos/std_algorithm_iteration.html#fold

Example: calculate the product of numbers in a list. If the list is empty, then the product is 1 by definition.

(1) fold()
import std.stdio;
import std.algorithm; // fold()

void main()
{
    int[] numbers = [1, 2, 3, 4, 5];

    // numbers cannot be empty; the 1st element is the seed
    int result1 = numbers.fold!("a * b");
    int result2 = numbers.fold!((a, b) => a * b);

    // numbers can be empty; the provided value (1) is the seed
    int result3 = numbers.fold!("a * b")(1);
    int result4 = numbers.fold!((a, b) => a * b)(1);

    writeln(result1); // 120
    writeln(result2); // 120
    writeln(result3); // 120
    writeln(result4); // 120
}
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2025 September 04, 18:12