« first day (322 days earlier)      last day (2808 days later) » 

9:39 AM
@Tunaki Got a dumb Java question, can I use your brain power?
 
sure
 
Given the following,
private Pair<Integer, Integer>[] weekData = new Pair[7];
 
private Pair is balls
3
 
Nope
 
(From javafx.util.Pair)
 
9:41 AM
Don't continue.
 
@AndrasDeak Oh gawd xD
 
Remove that code.
 
Sam
rofl
 
@Tunaki Am I doing something obviously wrong? xD
 
Array of a generic type, that can't work
Use a list
or
don't use Pair to begin with :)
 
9:43 AM
Is there any way to properly represent a sequence of 7 pairs of integers then?
 
double array?:P
 
int[2][7]
 
Meeeh
 
29
Q: Java 1.6: Creating an array of List<T>

MikeWhy can't I create an array of List ? List<String>[] nav = new List<String>[] { new ArrayList<String>() }; Eclipse says "Cannot create a generic array of List" or ArrayList<String>[] nav = new ArrayList<String>[] { new ArrayList<String>() }; Eclipse says "Cannot create a generic array of A...

 
Sam
@Tunaki Does java support jagged arrays?
 
9:44 AM
yep
 
Okay, so now I need to fill values in there
Seems like there's no push in Java
 
what kind of values?
 
Integers. By pairs.
Given it's data over a week, fill values day by day if you wish
 
Sam
@Tunaki Ask andras
 
@Sam rofl
 
9:47 AM
The long way
int[][] data = new int[7][2];
data[0][0] = myFirstXValue;
data[0][1] = myFirstYValue;
 
For now I've butchered some private int remainingValuesToFill = 7; which I personally find utterly disgusting
Oh gawd so that is the way
 
The short way
 
@Sam probably g monads
 
@AndrasDeak Monads and Gonads is actually a talk of Brendan Eich
 
9:48 AM
int[][] data = { { firstX, firstY }, { secondX, secondY }, ... }
 
Sam
lol
 
@Tunaki that's not long, that's int
 
@Tunaki Yeah but my filling function only fills day by day
 
Sam
What about using a map?
 
The intelligent way
 
9:48 AM
        this.weekData[7 - this.remainingValuesToFill][0] = min;
        this.weekData[7 - this.remainingValuesToFill][1] = max;
^ So it looks like this garbage
Also copy/paste error lel
 
refactor into non-garbage?:P
 
How is remainingValuesToFill computed?
 
@Tunaki Initialised at 7, decremented after above assignations
 
And min and max?
 
Function parameters
        private int[][] weekData = new int[7][2];
        private int remainingValuesToFill = 7;

        public int insertValue(int min, int max) {
            if(this.remainingValuesToFill == 0) throw new Error("All values for week already provided");

            if(!(min <= max)) throw new IllegalArgumentException("min value can't be higher than max value");
            this.weekData[7 - this.remainingValuesToFill][0] = min;
            this.weekData[7 - this.remainingValuesToFill][1] = max;
 
9:50 AM
Ah so they are the same always
 
Should probably be insertDayValues tho.
God writing Java after a three years pause is painful
 
just use python
 
well that looks about right
 
Sam
just use C#
LINQ all the things
 
what do you find ugly? :)
Is insertValue necessary?
 
9:52 AM
it's not pythonic
 
having to actually store the remaining values to be fed
@Tunaki Yeah, asked by the exercise for some weird reason
 
is there a reason why you're not keeping track of valuesFilled instead, master Yoda?
 
@AndrasDeak Because my brain was low on coffee when I wrote this xD
 
refactoring
 
9:54 AM
meh
in that case
I'd use a use List<int[]>
or
do some OOP
 
and can't you set the 2-element array part in one assignment? Something lke this.weekData[this.valuesFilled] = {min, max}?
 
@Tunaki I didn't want to have to redefine a whole new type for something so simple
@AndrasDeak Can I?
 
I'm asking, I don't know java:)
 
Maybe new int[2] {min, max}
 
probably not, but perhaps yes
 
9:56 AM
@Tunaki Yeah but to me having it clearly limited to 7 is clearer
 
Sam
Does java support anonymous objects?
 
        private List<int[]> weekData = new ArrayList<>();
        private int maxValue = 7;

        public int insertValue(int min, int max) {
            if(weedData.size() >= maxValue) throw new KyllException("All values for week already provided");

            if(min > max) throw new IllegalArgumentException("min value can't be higher than max value");
            weekData.add(new int[] { min, max });
        }
 
Sam
Or tuples, I guess they'd work too
 
and then, I'd even go OOP
 
I imagine Tuna going OOP OOP OOP running around like Zoidberg
 
9:57 AM
Maybe create a WeekData class, with 2 attributes min and max
 
@Tunaki cc @Magisch heh
 
@Sam there are no tuples no
 
Sam
:(
 
"For good reason"
 
Sam
Ha
 
9:59 AM
= too much work to implement
 
Sam
Yep
 
65
Q: Does Java SE 8 have Pairs or Tuples?

necromancerI am playing around with lazy functional operations in Java SE 8, and I want to map an index i to a pair / tuple (i, value[i]), then filter based on the second value[i] element, and finally output just the indices. Must I still suffer this: What is the equivalent of the C++ Pair<L,R> in Java? in...

^ answered by an OpenJDK dev
 
Sam
> On the other hand, having a Pair class adds to the temptation of creating complicated data structures [...]
 
it does
Hopefully, those concerns will be resolved in Java 10 (and project Valhalla)....
 
@Tunaki nice
@Tunaki the good old "hopefully the future will be better" fallacy:P
 
10:06 AM
@AndrasDeak Hey, it worked for ES6 in JS
 
Uuuh
How do you initialise an instance of an inner class?
 
I think you're asking the wrong question
 
XY problem?!
 
Probably.
I may have no idea what this inner class business is
 
10:08 AM
1049
Q: Java inner class and static nested class

OmnipotentWhat is the main difference between an inner class and a static nested class in Java? Does design / implementation play a role in choosing one of these?

 
closes Kyll as unclear
 
you probably want a nested class
 
Ah
Gotta first instanciate the outter class
Screw that, hoisting
 
There's no point in having an inner class like that really. They're nice when used as anonymous or local class
but if you want to instantiate one, I assume you're using it as a bastard nested class
 
Yeah
So let's not
 
10:13 AM
the bastard
 
Mh, gotta find the absolute difference between the smallest and largest value
 
are you having mathematical difficulties?
 
Not really
Thinking how I could reduce it properly functionally
 
if Timmy has 5 apples...
 
And if Java can even do that
 
Sam
10:16 AM
@AndrasDeak Time to call gunr
 
heh:D
he's probably in a meeting
 
In JS I'd use reduce and have some fun
In JS I'd use reduce and have some fun
^ Yay for race conditions
 
would you?
 
Sam
Isn't there a Math.abs function?
 
his issue is with running along the 7 days, I believe
 
10:18 AM
@Sam Yeah but that's not the issue
 
doing that elegantly
 
Sam
Ah right
 
^ yes
Goddamn ninjas
 
Sam
xD
 
I'm not sure you can do it elegantly
you need to loop over them, since you need the mins separately and the maxes separately
and you need to keep track of the history
 
10:20 AM
Yeah but that's ugly
A nice reduce with an accumulator would be so much more beautiful
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
This is not intended to confuse my teacher, should he ever review this
 
@Kyll Java has streams, and reduce.
What are you trying to do?
 
The equivalent of this JS:
writing
 
Lunch time (lol, sorry)
 
Sam
lol
 
Write it nonetheless, I'll respond when I get back :D
 
10:24 AM
xD
 
10:34 AM
Not sure why acc is undefined there o_o
const weekData = [
  [0, 10],
  [8, 15] //etc 7 times
]

const minMax = weekData.reduce((acc, currentDay) => {
  currentDay.forEach(temperature => {
    if(temperature < acc.min) acc.min = temperature
    if(temperature > acc.max) acc.max = temperature
  })
}, {min: Infinity, max: -Infinity})

console.log(minMax.max - minMax.max)
 
10:46 AM
I've just been pointed to this livestream and the twitch-plays-pokemon-esque culture surrounding it
 
wa
... damn
OH SHIT ATRUCK
 
@Kyll the weekdata may contain more than 2 numbers?
 
@MadaraUchiha No, only 2
No idea why acc is undefined when it seems I've defined an initial value
Probably something dumb, can't find it
 
11:02 AM
where did you define the initial value there?
off-screen?
 
class TempRange {

  private float min;
  private float max;

  public TempRange(float min, float max) {
    this.min = min;
    this.max = max;
  }

  // getters, setters
}

class Main {
  public static void main(String[] args) {
    List<TempRange> data = Arrays.asList(
      new TempRange(0, 10),
      new TempRange(8, 15)
      // etc
    );

    TempRange totalRange = data.stream()
      .reduce((acc, current) -> {
        if (current.getMin() < acc.getMin()) { current.setMin(acc.getMin()); }
 
@AndrasDeak {min: Infinity, max: -Infinity}
 
oh, missed that
 
@MadaraUchiha Oooh, that is sexy
 
Probably missing a bracket somwhere
 
11:05 AM
brace yourself, syntax errors are coming
 
Will try that then
Any idea why my JS code crashes? Can't find any issue with it
 
@Kyll You aren't returning anything from the reducer.
 
God fucking damnit
 
undefined.max = temperature == TypeEror
I haven't been here in a long time :o
 
Yep!
afk
 
11:25 AM
So @Kyll
I'm back
Madara has the idea, go OOP!
without the setters though
immutable!
@MadaraUchiha oh no no no no non
don't use reduce like that
 
@Tunaki Yeah, it would probably be a better idea to make a new instance instead of mutating the accumulator
But I got lazy :D
Something like
 
data.stream().min(Comparator.comparingInt(TempRange::getMin));
 
(acc, current) ->
  new TempRange(Math.min(acc.getMin(), current.getMin()), Math.max(acc.getMax(), current.getMax())
@Tunaki No, that won't do.
He's looking for the difference between the highest max and the lowest min
 
oh
well then
 
The reducer I put up most recently would end up with a TempRange with the desired values
All you need to do than is totalRange.getMax() - totalRange.getMin()
@Tunaki No
 
11:30 AM
I see
 
[[0, 10],
[8, 15]] ==> 15 - 0 = 15
 
Very well, a bit more wordy
int[] minimax = data.stream().collect(() -> new int[2], d -> { i[0] = Math.min(i[0], d.getMin()); i[1] = Math.max(i[1], d.getMax()) }, (d1, d2) -> { d1[0] = Math.min(d1[0], d2[0]); d1[1] = Math.max(d1[1], d2[1]); return d1 }; int result = minimax[1] - minimax[0]. Sigh.
but then, just iterate twice
will be simpler and really the same perf
 
When doing Java, I prefer sticking to OO structures instead of native ones.
Java's arrays suck.
If it were Clojure though :D
 
Yeah
Either you do that or you define your own collector
 
Yeah, which is just as verbose.
 
11:34 AM
Yup...
 
I'm growing to like Clojure a lot, actually.
Deliver a jar, no one has to know...
 
The easier being int result = data.stream().max(comparingInt(TempRange::getMax)).flatMap(max -> data.stream().min(comparingInt(TempRange::getMin)).map(min -> max - min)).orElse(defaultResultWhenNoData);
 
Let's face it, the easiest is
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
for (int[] datum : data) {
  min = Math.min(datum[0], min);
  max = Math.max(datum[1], max);
}
return max - min;
 
good old for loop
 
We're just being overly fancy here :D
If that's the extent of the problem, that's how I would do it
 
11:40 AM
Agree
 
If there's more to it, modelling an object around it sounds like a good idea.
 
it's Integer.MIN_VALUE but yeah
 
@MadaraUchiha the nice thing is that this will return 1 if there are no value :)
overflow thingy :D
 
public static int min(int ...ns) {
  return Arrays.stream(ns).reduce(Math::min);
}

public static int max(int ...ns) {
  return Arrays.stream(ns).reduce(Math::max);
}
Pretty
 
11:44 AM
returns an OptionalInt
 
@Tunaki Right
Lacks initial value
But you catch my drift :P
 
public static OptionalInt min(int ...ns) {
  return Arrays.stream(ns).min();
}
 
int min = Arrays.stream(data).map(datum -> datum[0]).min();
int max = Arrays.stream(data).map(datum -> datum[1]).max();
Also possible
 
yes
that looks nicer
but it returns that OptionalInt which you need to handle, just in case
 
11:51 AM
We're not going to get something as simple as the for loop
int res =
	Arrays.stream(data)
		  .map(i -> i[0])
		  .max(naturalOrder())
		  .flatMap(max ->
		  	Arrays.stream(data)
		  		  .map(i -> i[1])
		  		  .min(naturalOrder())
		  		  .map(min -> max - min)
		  ).orElse(default);
with all the boxing going around...
so really, why use this ^ or this v
public static void main(String[] args) {

	class TempMinMaxCollector {
		IntSummaryStatistics minStats;
		IntSummaryStatistics maxStats;
		void accept(int[] datum) {
			minStats.accept(datum[0]);
			maxStats.accept(datum[1]);
		}
		TempMinMaxCollector combine(TempMinMaxCollector other) {
			minStats.combine(other.minStats);
			maxStats.combine(other.maxStats);
			return this;
		}
		OptionalInt finisher() {
			return minStats.getCount() == 0 ? OptionalInt.empty() : OptionalInt.of(maxStats.getMax() - maxStats.getMin());
blargh
 
12:32 PM
Heh
 
it's horrible
 
 
3 hours later…
3:33 PM
o_o
 
4:03 PM
bottom line, use a loop
:)
 
 
2 hours later…
5:33 PM
Mh, I wonder if something like Math.min(...new int[] {1, 2, 3}) is possible in Java
 
 
1 hour later…
user3956566
6:49 PM
@Kyll I'm here!
 
Lady
It's like 5am for you -_-
Are you that excited?
 
user3956566
I know!
 
user3956566
skype?
 
user3956566
yes! re- excited
 
Soon? Gotta eat before. In 20 minutes?
 
user3956566
6:50 PM
sure
 
Thanks lady
 
user3956566
thanks smelly small mammal ;)
 
user3956566
@Tunaki will you go and read slack!
 
Tunaki be summoned here
To then be summoned somewhere else
To then be summoned somewhere else again
 
I have been summoned.
 
user3956566
6:52 PM
ah my magic spell worked
 
Yes. Now go check Slack.
 
I am transporting myself to Slack.
 
user3956566
read slack, there is news!
 
user3956566
lol
 
Opening a new tab...
Selecting the favorite...
Loading...
 
6:52 PM
I have it pinned
 
Arrived.
 

« first day (322 days earlier)      last day (2808 days later) »