Row.setField returning row itself

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Row.setField returning row itself

Flavio Pompermaier
Hi all,
many times I had the feeling that allowing Row.setField() to return the
modified object instead of void would really make the (Java) code cleaner
in a very unobtrusive way.
For example, I could write something like:

DataSet<Row> columnData = input.map(value -> new Row(1).setField(0, value))

instead of:

DataSet<Row> columnData = input//
        .map(value -> {
          Row r = new Row(1);
          r.setField(0, value);
          return r;
        })

What do you think?
May I open a JIRA issue about it?

Best,
Flavio
Reply | Threaded
Open this post in threaded view
|

Re: Row.setField returning row itself

Chesnay Schepler-3
I can see that this would be convenient but please find a better
example; yours can be solved easily using "Row.of(value)".

On 22/03/2019 12:26, Flavio Pompermaier wrote:

> Hi all,
> many times I had the feeling that allowing Row.setField() to return the
> modified object instead of void would really make the (Java) code cleaner
> in a very unobtrusive way.
> For example, I could write something like:
>
> DataSet<Row> columnData = input.map(value -> new Row(1).setField(0, value))
>
> instead of:
>
> DataSet<Row> columnData = input//
>          .map(value -> {
>            Row r = new Row(1);
>            r.setField(0, value);
>            return r;
>          })
>
> What do you think?
> May I open a JIRA issue about it?
>
> Best,
> Flavio
>

Reply | Threaded
Open this post in threaded view
|

Re: Row.setField returning row itself

Chesnay Schepler-3
You could even use a method reference here: "map(Row::of)"

On 22/03/2019 12:33, Chesnay Schepler wrote:

> I can see that this would be convenient but please find a better
> example; yours can be solved easily using "Row.of(value)".
>
> On 22/03/2019 12:26, Flavio Pompermaier wrote:
>> Hi all,
>> many times I had the feeling that allowing Row.setField() to return the
>> modified object instead of void would really make the (Java) code
>> cleaner
>> in a very unobtrusive way.
>> For example, I could write something like:
>>
>> DataSet<Row> columnData = input.map(value -> new Row(1).setField(0,
>> value))
>>
>> instead of:
>>
>> DataSet<Row> columnData = input//
>>          .map(value -> {
>>            Row r = new Row(1);
>>            r.setField(0, value);
>>            return r;
>>          })
>>
>> What do you think?
>> May I open a JIRA issue about it?
>>
>> Best,
>> Flavio
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Row.setField returning row itself

Flavio Pompermaier
You're right Chesnay, I didn't remember that .of was introduced :(
Sorry!

On Fri, Mar 22, 2019 at 12:35 PM Chesnay Schepler <[hidden email]>
wrote:

> You could even use a method reference here: "map(Row::of)"
>
> On 22/03/2019 12:33, Chesnay Schepler wrote:
> > I can see that this would be convenient but please find a better
> > example; yours can be solved easily using "Row.of(value)".
> >
> > On 22/03/2019 12:26, Flavio Pompermaier wrote:
> >> Hi all,
> >> many times I had the feeling that allowing Row.setField() to return the
> >> modified object instead of void would really make the (Java) code
> >> cleaner
> >> in a very unobtrusive way.
> >> For example, I could write something like:
> >>
> >> DataSet<Row> columnData = input.map(value -> new Row(1).setField(0,
> >> value))
> >>
> >> instead of:
> >>
> >> DataSet<Row> columnData = input//
> >>          .map(value -> {
> >>            Row r = new Row(1);
> >>            r.setField(0, value);
> >>            return r;
> >>          })
> >>
> >> What do you think?
> >> May I open a JIRA issue about it?
> >>
> >> Best,
> >> Flavio
> >>
> >
> >
>
>