Jira (PUP-11427) Iterable behavior of Integers not documented?

9 views
Skip to first unread message

Corey Hickey (Jira)

unread,
Jan 5, 2022, 7:51:01 PM1/5/22
to puppe...@googlegroups.com
Corey Hickey created an issue
 
Puppet / Improvement PUP-11427
Iterable behavior of Integers not documented?
Issue Type: Improvement Improvement
Affects Versions: PUP 7.12.1
Assignee: Unassigned
Components: Docs
Created: 2022/01/05 4:50 PM
Priority: Normal Normal
Reporter: Corey Hickey

I discovered, entirely by accident, that an Integer is an Iterable which expands to the range from zero to one less than the Integer. I can find this in the code and it's clearly an intended behavior:

https://github.com/puppetlabs/puppet/blob/7.13.1/lib/puppet/pops/types/iterable.rb#L44
https://github.com/puppetlabs/puppet/blob/7.13.1/lib/puppet/pops/types/iterable.rb#L92

I can't find this documented at all, though. Unless I'm missing something, the closest I can find is references to the Iterable type, though these pages don't enumerate what the type contains:
https://puppet.com/docs/puppet/7/functions_iterative.html
https://puppet.com/docs/puppet/7/lang_data_abstract.html#iterable-data-type

Thanks,
Corey

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

Josh Cooper (Jira)

unread,
Jan 6, 2022, 11:58:01 AM1/6/22
to puppe...@googlegroups.com
Josh Cooper commented on Improvement PUP-11427
 
Re: Iterable behavior of Integers not documented?

I knew you can define a parameterized Integer type and iterate that (like a range):

$ bx puppet apply -e 'Integer[0,1].each |$i| { notice($i) }'
Notice: Scope(Class[main]): 0
Notice: Scope(Class[main]): 1

But I didn't know you could iterate the integer directly:

$ bx puppet apply -e '2.each |$i| { notice($i) }'
Notice: Scope(Class[main]): 0
Notice: Scope(Class[main]): 1

Note there seems to be an off-by-one issue though. The comment says it yields the number, but it only yields up to, but not including the number, which is surprising given that Integer[0, 1] is inclusive by default.

Corey Hickey (Jira)

unread,
Jan 6, 2022, 5:54:02 PM1/6/22
to puppe...@googlegroups.com
Corey Hickey commented on Improvement PUP-11427

I'd say the comment is ambiguous; it's hard to know exactly since English doesn't describe ranges very well. smile.png

I do like the current behavior, though, for what I'm doing. Basically:

class foo (
    Integer[1] $num_instances,
) {
    $num_instances.each |$instance| {
        foo::instance { $instance:
            bar => 'baz',
        }
    }
}

Ciprian Badescu (Jira)

unread,
Jan 10, 2022, 10:21:01 AM1/10/22
to puppe...@googlegroups.com

Heston Hoffman (Jira)

unread,
Jan 13, 2022, 12:52:01 PM1/13/22
to puppe...@googlegroups.com

I'm going to move this to DOCUMENT so it's more visible to the docs team

Reply all
Reply to author
Forward
0 new messages