How to walk over two arrays by ref in beautyfull way?

Russel Winder russel at winder.org.uk
Mon Jun 10 10:17:12 UTC 2019


On Mon, 2019-06-10 at 08:02 +0000, vitalfadeev via Digitalmars-d-learn
wrote:

[…]

Perhaps I am missing something that is critical to the example, but I
rewrote the code as:

   import std.algorithm: map;
   import std.stdio: writeln;

   bool false_cb() { return false; }
   bool true_cb() { return true; }

   void main() {
       auto checkers = [&false_cb, &false_cb, &true_cb];
       auto result = map!(a => a())(checkers);
       writeln(result);
   }

This avoids the assumption that 0 is false and 1 is true. Also it makes
use of D map which seems to me what is happening at the core of the
code – using foreach and zip or lockstep just seems to be implementing
map. But as I say, I may be missing something.

-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20190610/1ee8e565/attachment-0001.sig>


More information about the Digitalmars-d-learn mailing list