[ 
https://issues.apache.org/jira/browse/NUMBERS-215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18117065#comment-18117065
 ] 

Gilles Sadowski commented on NUMBERS-215:
-----------------------------------------

bq. [...] still an instance method [...]

Yes, because it's contains a "vararg"; to make it {{static}}, one has to pass 
{{k}}, but that argument must come before the "vararg" one; and this would 
entail a slightly inconsistent API:
{code}
of(int n, int k)
{code}
vs
{code}
stream(int k, T... items)
{code}

Since the "vararg" is syntactic sugar for when the application developer 
explicitly expands the sequence of items, I think that there is no harm in 
having to write
{code}
List<List<String>> all = Stirling.S2.of(4, 2).stream("A", "B", "C", "D")
    .collect(Collectors.toList());
{code}

The alternative would be to remove the "vararg" version.

We could provide the array version:
{code}
stream(T[] items, int k)
{code}
so that the developer could write
{code}
List<List<String>> all = Stirling.S2.stream(new String[] {"A", "B", "C", "D"}, 
2)
    .collect(Collectors.toList());
{code}
But that becomes longer than the original version!
Moreover, the redundancy of passing (explicitly) {{n}} to {{of(n, k)}} and 
(implicitly) to {{stream}} might useful in early detection of a programming 
error (e.g. where the same {{S2}} instance would be used to iterate over 
different list of items that are assumed to have the same size).

> Stirling partitions generator
> -----------------------------
>
>                 Key: NUMBERS-215
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-215
>             Project: Commons Numbers
>          Issue Type: New Feature
>          Components: combinatorics
>            Reporter: Gilles Sadowski
>            Assignee: Gilles Sadowski
>            Priority: Minor
>             Fix For: 1.4
>
>
> Would it be useful to provide functionality to *iterate* over the partitions 
> defined by "Stirling number of the second kind" (i.e. all partitions into K 
> subsets, of a set of N elements)?
> Code would be in a nested static class of the existing 
> [{{Stirling}}|https://commons.apache.org/proper/commons-numbers/commons-numbers-combinatorics/apidocs/src-html/org/apache/commons/numbers/combinatorics/Stirling.html]
>  class:
> {code}
> public final class Stirling {
>     // ...
>     public static final class S2 implements Iterable<List<List<Integer>> {
>          // ...
>          public static S2 of(int n, int k) {
>              // ...
>          }
>     }
> }
> {code}
> I have a potential use case (for very small "N").



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to