Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5053A200D21 for ; Mon, 2 Oct 2017 07:10:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4EC461609D9; Mon, 2 Oct 2017 05:10:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9466B1609C8 for ; Mon, 2 Oct 2017 07:10:09 +0200 (CEST) Received: (qmail 88798 invoked by uid 500); 2 Oct 2017 05:10:08 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 88789 invoked by uid 99); 2 Oct 2017 05:10:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Oct 2017 05:10:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 3EECB1A03FE for ; Mon, 2 Oct 2017 05:10:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id vezJTc-Y0AGt for ; Mon, 2 Oct 2017 05:10:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C206660FC8 for ; Mon, 2 Oct 2017 05:10:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id D1C59E0F41 for ; Mon, 2 Oct 2017 05:10:03 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id AA7D6242CB for ; Mon, 2 Oct 2017 05:10:00 +0000 (UTC) Date: Mon, 2 Oct 2017 05:10:00 +0000 (UTC) From: =?utf-8?Q?Ondra_=C5=BDi=C5=BEka_=28JIRA=29?= To: notifications@freemarker.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (FREEMARKER-37) ability to skip iteration in a list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 02 Oct 2017 05:10:10 -0000 [ https://issues.apache.org/jira/browse/FREEMARKER-37?page=3Dcom.atlass= ian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1= 6187662#comment-16187662 ]=20 Ondra =C5=BDi=C5=BEka edited comment on FREEMARKER-37 at 10/2/17 5:09 AM: ---------------------------------------------------------------- I agree that just having {{<#continue>}} might lead to an unexpected/undefi= ned behavior with things like counters, separators etc. How about having {{<#continue>}} and {{<#skip>}} ? {{<#continue>}} would = count as item used (increment the counter), {{<#skip>}} would not. This wou= ld pass the responsibility to decide whether to increment the counter or no= t to the user. It makes sense, because the user knows whether he uses {{is_= even_item}} for coloring table rows, and whether that was already taken car= e of (then they would use {{<#continue>}}) or not (then he would use {{<#sk= ip>}}). I.e. {code} <#list 10..15 as num> <#if num =3D=3D 10>=20 <#continue> <#if num =3D=3D 11>=20 <#skip> [${num.index}] =3D=3D ${num}, ${num.count} items passed, is_first =3D = ${num.is_first?c} {code} This would print=20 2 =3D=3D 12, 1 items passed, is_first=3Dfalse (I hope I computed right :) ... Because the {{.counter}} would increment only if the loop is finished or co= ntinued, {{is_first}} would derive from the {{counter =3D=3D 0}}.=20 Similarly, {{is_even_item}} and {{is_odd_item}} would check the counter rat= her than index. {{is_last}} would probably have to rely on {{index}}. Similarly, separators could appear if {{couter > 0 and index < size-1}}, an= d, well, the user would have to have some common sense not to expect the se= parator appear if he uses {{<#skip>}} before {{<#sep>}}.=20 was (Author: pekarna): I agree that just having {{<#continue>}} might lead to an unexpected/undefi= ned behavior with things like counters, separators etc. How about having {{<#continue>}} and {{<#skip>}} ? {{<#continue>}} would = count as item used, {{<#skip>}} would not. This would pass the responsibili= ty to decide whether to increment the counter or not to the user. It makes = sense, because the user knows whether he uses {{is_even_item}} for coloring= table rows, and whether that was already taken care of (then they would us= e {{<#continue>}}) or not (then he would use {{<#skip>}}). I.e. {code} <#list 10..15 as num> <#if num =3D=3D 10>=20 <#continue> <#if num =3D=3D 11>=20 <#skip> [${num.index}] =3D=3D ${num}, ${num.count} items passed, is_first =3D = ${num.is_first?c} {code} This would print=20 2 =3D=3D 12, 1 items passed, is_first=3Dfalse (I hope I computed right :) ... Because the {{.counter}} would increment only if the loop is finished or co= ntinued, {{is_first}} would derive from the {{counter =3D=3D 0}}.=20 Similarly, {{is_even_item}} and {{is_odd_item}} would check the counter rat= her than index. {{is_last}} would probably have to rely on {{index}}. Similarly, separators could appear if {{couter > 0 and index < size-1}}, an= d, well, the user would have to have some common sense not to expect the se= parator appear if he uses {{<#skip>}} before {{<#sep>}}.=20 > ability to skip iteration in a list > ----------------------------------- > > Key: FREEMARKER-37 > URL: https://issues.apache.org/jira/browse/FREEMARKER-37 > Project: Apache Freemarker > Issue Type: Improvement > Reporter: Ivan Levchenko > > Sorely missing ability to skip through an iteration of a list and continu= e on with the rest of the list. would like to write clean code like this: > <#list collection as element> > <#if element.attr1 =3D=3D "some_value">=20 > <#continue /> <#-- skip over this item and run next item= in loop --> > > do stuff here > > Thanks! -- This message was sent by Atlassian JIRA (v6.4.14#64029)