How To: Passing curried functions around

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 11 14:04:40 PDT 2015


On 09/11/2015 01:07 PM, Bahman Movaqar wrote:
 > On Friday, 11 September 2015 at 18:39:15 UTC, Ali Çehreli wrote:
 >> >> import std.stdio;
 >> >>
 >> >> bool isEven(int n) {
 >> >>     return !(n % 2);
 >> >> }
 >> >>
 >> >> int readValidInt(alias validator)(string prompt) {
 >>
 >> readValidInt() is a function template that takes two information:
 >>
 >> 1) The validator as its alias template parameter. alias template
 >> parameter allows it to work with anything that can be called.
 >
 > I read "alias and with" chapter of the book to understand this but
 > couldn't find any such use for `alias` there.  Does using `alias`
 > instead of a type makes the parameter a `callable`?

Sorry for the confusion. :) The same keyword has a different use with 
templates:

 
http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.alias,%20template%20parameter

Ali



More information about the Digitalmars-d-learn mailing list