Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99759 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41034 invoked from network); 5 Jul 2017 10:51:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2017 10:51:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:37407] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/8B-15131-FA4CC595 for ; Wed, 05 Jul 2017 06:51:28 -0400 Received: by mail-wm0-f49.google.com with SMTP id i127so162443577wma.0 for ; Wed, 05 Jul 2017 03:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=iOVFuWp5Avl78Ccundl8vsRLWTQ3EAiThlnO6cjO4RQ=; b=er1+WJnEt5aoCwJvBmSyddBOopuvkSYPVPAr2pi1i5WF4LZ/IFjx7I7VRR4DQZxhQA Q5v89cU7eHPnbUhXYgn5PgQ1FgQDWKLVyT2hGrvr7GWkWTUefm8tYOSNRZBMM78wnxrC W50IvU3LmP9vOeh2CLs36oVi5WQbI+ZPxehNGHyaZIYBmldZewpi7dLDQh3w5O4NvCZd +XqhfE+l9ISFdaWUh8leQPAfGJdp3xOizfe5IS76EOegD8o7Nxxktyn7qDG3yzDPAc3D 1/YjG8NbYg+gRCfn4AwkzC2+6JnNm4jPLtI/ef8yze7yfPlx/K/agTbyHGwTEgsKqkDS TQaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=iOVFuWp5Avl78Ccundl8vsRLWTQ3EAiThlnO6cjO4RQ=; b=czGw4J/KBMZ+MkReK7CAehyxLOXhP9/F0ta/JxH15p7OY1BsljqEzmiP9c9N2vtGpK u8OiNQOnHweIG/PnqQfWX52e+FX3v7wwR0/8AAT/kK+DX/VDFZzxJl5XxetnxO4ABX5A BybnGcRodk5EFy0Ql3IxVlood3x1xTixKsZpaoYt5d/RfLoFedkUx8VQF3a6rUYJIXgc mngOHJUyfpgVOLjG7nE37vOo9YwE4K4zy8MVswHcT1jKbPtBJtRZ4508UTLrmbqxEXAf C2NHKGOddBwEqAhnTmi+5JIO7d0bUl/+Rq31nOTrrLRYZaUDo3LPPGQ1OMTJUGTx5hOY jXvg== X-Gm-Message-State: AKS2vOy8CTuGE5Iv7SpyRclE8IH7j46CXrs2tEcM/REzQjTKdhi9WIQd dNNI+7A0D6DjPpvz X-Received: by 10.28.113.214 with SMTP id d83mr33427001wmi.62.1499251884551; Wed, 05 Jul 2017 03:51:24 -0700 (PDT) Received: from android-c07b90b023759a5a (host86-160-21-49.range86-160.btcentralplus.com. [86.160.21.49]) by smtp.gmail.com with ESMTPSA id y9sm23235246wry.32.2017.07.05.03.51.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2017 03:51:23 -0700 (PDT) Date: Wed, 05 Jul 2017 11:51:19 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: <1499095625.19635.52.camel@schlueters.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: Subject: Re: [PHP-DEV] "Reader" as alternative to Iterator From: rowan.collins@gmail.com (Rowan Collins) On 3 July 2017 16:58:16 BST, Andreas Hennings wrote= : >My motivation was to be able to use iterators and readers >interchangeably=2E >Readers are easier to implement as classes=2E >Iterators have the benefit of the generator syntax=2E >The idea is to have a library where some stuff is implemented as >reader classes, and some other things are implemented as iterator >classes=2E > >Then for the actual operational code, I need to choose to use either >iterator syntax or reader syntax=2E So either I need adapters for all >iterators, or I need adapters for all readers=2E An alternative to adapters in this case might be a Trait that allows you t= o write the class as a Reader, but turn it into a fully-functioning Iterato= r with one line of code=2E If you always call your read method read() you o= nly need a single adapter which calls that at the appropriate times and buf= fers the value to know if it's reached the end=2E That adapter could be "pa= sted" by a Trait into each class where read() is defined, and read() could = even be private=2E Regards, --=20 Rowan Collins [IMSoP]