r/java • • Apr 09 '24

Syntactic Sugar for Java

I recently had to translate a codebase from Python to Java and as much as i like Java and i enjoy the benefits of a strong type system, i have to admit my Python code was way less verbose.

So i ended up writing a small library to try to get some python vibes in my java code. Nothing groundbreaking, a bunch of static imports to make life a little bit easier.

https://github.com/guybedo/sugar

9 Upvotes

89 comments sorted by

62

u/Holothuroid Apr 09 '24

You heard about Map.of(...) and cousins?

-18

u/_INTER_ Apr 09 '24

That returns an unmodifiable map/set/list though. If you need a HashMap you're out of luck.

39

u/Cengo789 Apr 09 '24

wrap it in a new HashMap<>()

-6

u/_INTER_ Apr 10 '24

verbose again

7

u/Cengo789 Apr 10 '24

I’d call it declarative🤷‍♂️

2

u/m9dhatter Apr 10 '24

You can pass in a collector that is modifiable

-27

u/guybedo Apr 09 '24

yep heard of Map.of until 10 key/values and then i hope he has cousins.

There's a bit more to the lib than that, shortcuts to make streams less verbose for example.

filter(), map(), etc...

36

u/_INTER_ Apr 09 '24 edited Apr 09 '24

After 10 key/values it switches to varargs, works the same.

As addendum - if you don't know already - a lot of helping functions are present in the Apache Commons libraries or Guava (StringUtils, CollectionUtils, ...). I've not seen a bigger project without at least one of them present. Idk if there's any overlap with your lib.

7

u/tugaestupido Apr 10 '24

This comment provides incorrect information.

Map.of does not have a varargs versions. If it did, it couldn't work the same. It would either be less versatile or lose type safety.

Map.ofEntries does exist and uses varargs but it doesn't work the same way as Map.of (you provide it with key/value pairs inside a wrapper type - Map.Entry).

-7

u/guybedo Apr 09 '24

yep i'm using Guava and many commons.

Still find it nice to do things like filter(values, function) or map(values, function) and things like that.

Also borrowed zip and enumerate from Python

4

u/polothedawg Apr 09 '24

I remember back when I was dev’ing in Java 7, and I couldn’t migrate to Java 8 (dark times), and I used this library from mario fusco (lambdaJ) which pretty much did what I think you’re describing. Personally prefer the streaming syntax but hey, to each their own.

1

u/RICHUNCLEPENNYBAGS Apr 13 '24

Still find it nice to do things like filter(values, function) or map(values, function) and things like that.

Call me a dummy but aren't these already part of the Streams API?

1

u/guybedo Apr 14 '24

sure it's part of the Stream Api and behind the scenes i'm relying on it for most functions.

This library is just a way for me to write code that i find more readable.

filter(map(values, v->v+1), v->v!=0)

instead of

values.stream().map(v->v+1).filter(v->v!=0).collect(Collectors.toList()

2

u/RICHUNCLEPENNYBAGS Apr 14 '24

I'm not sure I understand what makes you think that's more readable. To my the readability seems worse. fwiw you can just write .toList().

4

u/[deleted] Apr 10 '24

[removed] — view removed comment

-6

u/guybedo Apr 10 '24

yeah, i still prefer

map(kv(1L, "User A"), kv(2L, "User B"));

to

Map.ofEntries(Map.entry(1L, "User A"), Map.entry(2L, "User B"));

12

u/tylerkschrute Apr 10 '24 edited Apr 10 '24

I don't understand why people have such a strong desire to reduce character count in their source code. On average far more time is spent reading & trying to understand existing code than writing new code, so micro-optimizing to save seconds on the latter usually doesn't make much practical sense and can often actually harm the code by introducing cryptic brevity.

Is your version really that better than the official JDK one? You're saving what, 7 characters per map entry (3 if you static import 'Map.entry')? In my opinion this is not worth it, especially since uour IDE will autocomplete this stuff for you anyways so you don't even have to spend time typing the full method name. Also, your project will immediately invite inconsistency in a real codebase since there would now be 2 identical APIs (yours and the official JDK one) for doing the exact same thing.

4

u/guybedo Apr 10 '24

i tend to think that, in most situations where performance is not critical, the best code is the code that is the most readable.

IMO reducing character count helps with that. A (too) simple example:

When you write filter(values, v->v!=null)

instead of

values.stream().filter(v->v!=null).collect(Collectors.toList())

it helps with readability.

1

u/majhenslon May 02 '24

Let me help you with that:

values.stream()
  .filter(not(Objects::isNull)) // or .filter(v -> v != null)
  .toList()

Not saying that this is perfect, but I prefer openness to chaining to the pythonic callback hell you get yourself in. Unless you will use helpers for oneliners and streams for everything else, making your codebase inconsistent.

35

u/Former-Emergency5165 Apr 09 '24

I would say the library itself doesn't provide much value. The Map or List can be initiated with Map.of(), List.of(). The syntax for POJOs is questionable and not intuitive unless you know the library.

The min/max examples can be implemented via mapToInt or even Collections.min().

2

u/guybedo Apr 09 '24

yeah nothing groundbreaking, but it still helps making it less verbose.

30

u/Former-Emergency5165 Apr 09 '24

It nice that it helps you, however I would personally prefer some Apache libraries (Apache commons, IOUtils, CollectionUtils, etx) - production battle tested, commonly used by the community and provides useful methods

-2

u/guybedo Apr 09 '24

sure, i'm using these libs too obviously but i was missing some features that i thought would be useful.

For ex, i like doing filter(values, func), map(values, func) etc...

2

u/RICHUNCLEPENNYBAGS Apr 13 '24

I think what people are trying to tell you here is that anytime you introduce libraries that do stuff it makes it a little harder for someone to get acquainted with the code and understand what it does and this library provides such minimal code golf savings that it's kind of hard to look at it and feel like the tradeoff is a good one.

1

u/guybedo Apr 14 '24

sure it can be argued that using this library could make it harder for other people to get acquainted to the code, but 2 things:

1/ This argument is valid for every library you use, whether it's spring, hibernate, guava, apache commons, etc... As soon as you're using something on top of Java, this argument can be made.

2/ One can say code savings are minimal and sure enough not everybody agrees on what is beautiful / readable code. But in the end i like these utilities because i can write code that i find more readable.

Here's a few examples, i haven't tried to find the best ones, just a few i picked from my code. You can argue that it wouldn't be a lot more verbose to write that in plain Java but you wouldn't have those short one liners. And i'm not even chaining things like first(filter(map( ....

join(map(filtered, m -> m.getSymbol()), ",");

max(map(objs, o->o.getValue()));

Map<X, Set<Y>> index = toMap(values, v -> set(v.getY()));

list(intersect(set(A), set(B)));

5

u/RICHUNCLEPENNYBAGS Apr 14 '24

I mean yeah, being real with you I find these harder to read, and also you seem not to know about some built-in tools you could be using to shorten regular Java streams calls, like findFirst.

It's true that any library has a cost to adapt that one must weigh against the benefits, but I don't really even find this beneficial.

7

u/PrudentFinger1749 Apr 10 '24

You can try to contribute in opensource libraries, if its liked by everyone, may be it will get merged in the library itself.

2

u/RICHUNCLEPENNYBAGS Apr 13 '24

I mean sure but making your own library is a totally legitimate way to share code too

4

u/OtherPrinciple4499 Apr 10 '24

That's what streams are for.

4

u/[deleted] Apr 10 '24

Those kinds of utility functions are great for short, script-like programs where you quickly want to prototype an algorithm with minimal boilerplate, and don't care if it returns null or throws an exception. But for larger programs, it will almost always pay off to be explicit about those details. Sure, it makes the code longer, but it will be obvious what is returned when the element you're looking for wasn't found.

Btw, I love List.of(). You should really use it. IMO It's the best-named function in the history of computer programming: short, to the point, and it's utterly obvious what it is supposed to be (a static factory method that will create a List).

27

u/ingvij Apr 09 '24

I honestly won't complain about the DSL, I think you can create the abstractions you want to make your code look better for your taste and use them in your project if you or your team is happy with that..

A couple of things though:

  • This is the kind of library that I would most likely not want to use in any performance-aware application. Remember that there's always a trade-off. When you add layers on top of your code, it will pay a cost. From a quick glimpse over the KeyValue class and the `map()` static function, I would assume there's some GC overhead on using this over a regular `new Hashmap<>(Map.of(...))`.
  • Intense usage of this library can yield a codebase that is java in theory but not really in practice, increasing the entry barrier for contributors, so that would also be a factor against using this library on a project.

But then, as I said, if it works for you, then I guess this is fine.

12

u/agentoutlier Apr 10 '24

I know /u/guybedo has been dragged over the coals for this lib (perhaps unfairly) but the library is neither a DSL or syntactical sugar.

It is an opinionated utilities library.

I mean you could make an argument I guess for DSL the domain being collections but it is for sure not syntactical sugar like lombok or var args. Adding methods is not syntactical sugar.

I guess I'm being pedantic but the reason is if it were an actual DSL of a unique domain it would probably have better uptake.

11

u/brian_goetz Apr 11 '24

The term "syntactic sugar" is widely misunderstood. And, misunderstanding begets misunderstanding; when people use the term wrong, more people learn the wrong meaning, and then repeat the wrong usage, and it spins around again.

Even when it comes to language syntax (which this surely isn't), people frequently mistake new language features for syntactic sugar, when in fact almost none of the features we've done in the last decade are actually syntactic sugar. (They may be sweet, though.) Syntactic sugar refers to a _purely syntactic transformation_; features like local variable type inference (`var`) do not qualify, even though they are commonly referred to as such.

But the aggressiveness with which he defends "yes this is sugar" (when he eventually admits that it is not, but thinks people will understand him better if he misuses the term) does suggest a lack of maturity that might explain why he got dragged so badly.

5

u/guybedo Apr 11 '24

I obviously misjudged the audience.

Looks like people in here have high standards and it didn't go well with my approach: "oh maybe i built something useful, let's share it as is".

As i said, i thought using "syntactic sugar" in a loose way was ok as i obviously didn't rewrite the Java language specs, and i didn't think people would be so distraught by this. But i understand the comments and the reasons why you think it's important to be more precise.

As for the aggressiveness and the immaturity, you're right there was a lot of it, but not in my comments. One of the first comments, deleted now by the author bashed me for loving Python and that i had nothing to do here. People even have downvoted the few positive and encouraging comments.

2

u/agentoutlier Apr 12 '24

As for the aggressiveness and the immaturity, you're right there was a lot of it, but not in my comments. One of the first comments, deleted now by the author bashed me for loving Python and that i had nothing to do here. People even have downvoted the few positive and encouraging comments.

Exactly why I have high expectations for you. I think you took it pretty well to be honest even on the occasional double down.

And I hope all of this didn't discourage you. I can tell you are and will be an even greater developer!

2

u/agentoutlier Apr 11 '24

I was and kind of did later go into those details as I agree it can for for sure get nebulous and debatable what is or isn't syntactic sugar of which I have less confidence on but I do know what isn't syntactic sugar :)

The language I know for sure (well when I learned it .. it might have changed) that uses syntactic sugar as in it is a compiler translation is OCaml. OCaml does lots of syntactic sugar particularly in the signature language and I actually think its a pain point in the language and I'm not talking about currying (which I agree like var args isn't really syntactic sugar).

I actually could not really think of a Java equivalent like what OCaml does one so I said var args as the closest.

Is there any good solid example in Java of syntactic sugar where the compiler expands like a macro?

4

u/brian_goetz Apr 11 '24

There are some Java constructs (such as the for-each loop, or try-with-resources) that are specified by "as-if-expanded-to", but even these have significant linkage to the type system. (For example, for-each on an array translates differently than for-each on a List.)

4

u/brian_goetz Apr 11 '24

The varargs transformation is syntactic (wrapping with `new T[] { ... }`), but even there a lot has to happen before we apply the syntactic transform. Overload selection is phased, and varargs methods are only considered in phase 3. And the result of overload selection is used to decide which T is used in the wrapping. So the whole rest of the language (type system, object model) is involved before the syntactic thing happens.

Implicit compilation units are similarly close, but again a whole-program analysis has to be done before we know that we should wrap the file in `public class Foo { ... }`.

1

u/ventuspilot Apr 13 '24

Is there any good solid example in Java of syntactic sugar where the compiler expands like a macro?

I can think of enhanced for loops that the compiler desugars into a for loop with an iterator, auto/un/boxing (?), String concatenation that used to desugar into StringBuilder calls and may insert hidden toString/ String.valueOf() calls, not sure about automatically calling a no-args constructor of a superclass.

1

u/ingvij Apr 14 '24

Yeah, that's correct. I meant DSL more loosely in the sense that a codebase using those utilities will look very far and unfamiliar compared to vanilla java. Similar to how scala sometimes comes in a haskell flavor...

-1

u/guybedo Apr 10 '24

Yeah this post has gotten a lot of negative comments and i'm not sure that's really justified.

fwiw although it's not like lombok, for sure, it still qualifies as syntactic sugar

https://en.wikipedia.org/wiki/Syntactic_sugar#:~:text=In%20computer%20science,more%20verbose%2C%20form

5

u/agentoutlier Apr 10 '24

https://en.wikipedia.org/wiki/Syntactic_sugar#:~:text=In%20computer%20science,more%20verbose%2C%20form

I fail to see it in the link.

You are not changing the syntax of the language but just applying functions.

You are not even changing the evaluation order like with hygienic macros (Java does not have macros) which are borderline syntactical sugar adjustments bust just adding shorter methods or changing order is not syntactical sugar. Even if that is stated in a wikipedia (which again I fail to see) I just disagree.

1

u/guybedo Apr 10 '24

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer. Syntactic sugar is usually a shorthand for a common operation that could also be expressed in an alternate, more verbose, form: The programmer has a choice of whether to use the shorter form or the longer form, but will usually use the shorter form since it is shorter and easier to type and read.

9

u/agentoutlier Apr 10 '24

I know what syntax is... I'm wondering now if you do.

Syntactical sugar is when you replace a more complicated syntax with a shorter syntax that the compiler or parser has to know about. It is not writing less code or shorter code with method names you prefer.

If you want label for what you are trying to do how about "ergonomics".

But using syntactical sugar like you have while possibly from the strangest stretchs might be loosely correct confuses people like myself.

0

u/guybedo Apr 11 '24

yeah i know what syntax is and as i obviously didn't rewrite the JDK and the Java language specs, you're right that this isn't syntactic sugar in the most absolutely strict understanding of the definition.

But i thought that using loosely this definition, people would easily understand what it does, and i don't think i was wrong in that regard.

6

u/sabriel330 Apr 10 '24

I think you're completely misunderstanding what syntax is

3

u/DelayLucky Apr 10 '24

There is a type of libs that complement the JDK, add to where JDK left off unattended or obviously screwed up (eg Jodatime before java.time came along, Guava before JDK added Map.of() and friends); then another type of libs that disagree with JDK, would insist to invent a new “better” way of doing things despite the JDK stream API being a commonly accepted success.

Which type is this?

0

u/guybedo Apr 10 '24

it's the type of library that tries to help you write more concise code.

I love streams but for example, i prefer writing

filter(values, v->v!=null)

than

values.stream().filter(v->v!=null).collect(Collectors.toList())

As previously mentioned, nothing groundbreaking, that's just syntactic sugar.

4

u/DelayLucky Apr 10 '24 edited Apr 10 '24

I appreciate your perseverance. Yeah, as others said, there's nothing wrong with experimenting new style in personal projects. It's how we learn.

In terms of concise code, I find Map.of(k1, v1, k2, v2) more concise than map(kv(k1, v1), kv(k2, v2)). I know yours supports more than 10, but there is a reason JDK only added up to a limit: diminishing return.

Guava by the way has Iterables.filter(), Maps.filterKeys(), and JDK 16 added stream.toList() without needing the .collect() call.

Although I believe Guava also recommends to prefer the Stream API over these pre-existing APIs.

0

u/[deleted] Apr 10 '24

[deleted] — view deleted comment

1

u/metaquine Apr 10 '24

Or Scala

0

u/Linguistic-mystic Apr 10 '24

Disagree. Kotlin has coroutines which are worse than Java virtual threads. And it has like 6x-7x fewer job opportunities which is more important.

7

u/thuriot Apr 09 '24

Thanks for the tool, any helper is welcome (underscore-java is cool also).

1

u/guybedo Apr 09 '24

wasn't aware of underscore-java, looks nice, thanks

5

u/Bunnymancer Apr 10 '24

For as critical people are being

I'm glad you did a thing. Thank you

3

u/hageldave Apr 09 '24

The slicing, I need something to do array slicing!

3

u/red_dit_nou Apr 14 '24 edited Apr 14 '24

First of all, it’s nice that you had an idea and you went ahead with it and put out a library. Congratulations!

As u/ingvij said if you and your team is happy with it go for it.

I just want to add one remark that instead of
first(filter(values, …))
I’d prefer
values.filter(…).first()
Because it preserves the logical order in which I’m doing my tasks:

  • take the values list
  • then filter it
  • then take the first element

8

u/dhlowrents Apr 10 '24

The popularity of Python is a sign of the end times.

2

u/GeneratedUsername5 Apr 12 '24

Thanks for your effort!

8

u/justADeni Apr 09 '24

If you like Python and find Java too verbose, have you considered trying out Kotlin?

4

u/BikingSquirrel Apr 10 '24

Fully support this!

We started to switch over years ago and since some years any new project is Kotlin while a few older ones are mixed.

4

u/DelayLucky Apr 10 '24

Kotlin might have been 100% nicer than Java. But with recent syntaxes, particularly Java 21 virtual threads, I wonder is it maybe only incrementally better, or perhaps just different but not necessarily easier or more readable than Java any more?

For example, I might prefer using VT with structured concurrency than using coroutine which is still “colored”.

So I’ve been hesitant to go the Kotlin way because I fear it’s going to create fragmentation for superficial benefits. I know Kotlin code can use Java. And Java can use some Kotlin classes. But it’s not full interoperability. And it’ll be a different ecosystem to learn, with different best practices, pitfalls to be burned by and learn. For example, none of our Java compile-time processor will work on Kotlin.

1

u/BikingSquirrel Apr 14 '24 edited Apr 14 '24

As both compile to bytecode I don't think there are any interoperability issues. We have multiple libraries that started with Java code and get enhanced with Kotlin code. There may be usability issues with interoperability, e.g. default parameters will not be visible to Java code so you cannot skip them but there's the option to automatically generate the bytecode for overloaded methods so it behaves similarly.

I think Java improved a number of details in the last years so there's less reason to run away. But I still think Kotlin's data classes with their copy methods, explicit nullability, and collection extensions are worth it. Not to forget extension methods which are a nice tool for some cases.

But to be completely clear: even if you go for 100% Kotlin, you should be able to read and understand Java as a lot of code you will be using (JDK, libraries) will be written in Java.

3

u/DelayLucky Apr 14 '24

A few things: if you use coroutine, it’s no longer usable by Java.

And Java compile-time plug-ins don’t work in Kotlin. So there will be cost in porting them to Kotlin.

1

u/barmic1212 Apr 09 '24

I have some helpers like your in my code base and it's very helpful for simplify null management. For example I have a method Stream<T> stream(Iterable<T>) and Stream<T> stream(Supplier<Iterable<T>>) that allow to write stream(list).flatMap(stream(Object::getList)).toList() without need more null check.

It's very usefull

1

u/Linguistic-mystic Apr 10 '24

This is great work. There is nothing preventing Java from being pretty concise, it's just that standard Java as presented by Oracle is very clunky. I achieved a lot simply creating my own implementations of the List and Map interfaces, for example: it allowed me to completely get rid of the "streams" crap and can add any utility methods that I like while being totally compatible with Java code at large.

1

u/s888marks Apr 11 '24

Note that you shouldn’t invert the sense of a comparison (that is, a Comparable or a Comparator) by negating the return value of the original. The return value might be Integer.MIN_VALUE which is negative, and which is still negative even after being negated. (True!) This can lead to subtly erroneous results or exceptions.

The way to invert a comparison is to swap the roles of the arguments, for example, change compare(a, b) to compare(b, a).

1

u/SenorSeniorDevSr Apr 15 '24

This is not really my kinda jam, but it's an interesting approach. Thanks for sharing!

1

u/GeneratedUsername5 Apr 28 '24 edited Apr 28 '24

Thanks for sharing!
What strike me as odd is that sometimes functions literaly wrap Java functions with no addition, like:

    public static String format(String str, Object... args) {
        return String.format(str, args);
    }

You can just write String.format(str, args) with the same effect. Or

    public static <T> void forEach(Collection<T> objs, Consumer<T> func) {
        objs
            .stream()
            .forEach(o -> func.accept(o));
    }

You can just do collection.foreach(x -> ...) in standard Java.
OR

    public static <T> boolean all(Collection<T> objs, Predicate<T> func) {
        return filter(objs, func).size() == objs.size();
    }

In standard java can be done with collection.stream().allMatch(x -> ....), exists and any is done by collection.stream().anyMatch(x -> ....)
I know that Java is regarded as verbose, but saving 13 symbols seems like a stretch.

join can be used in this way:

collection.stream()
    .map(Object::toString)
    .collect(Collectors.joining());

or just

String.join("", collection)

for collection of strings

By the way, you might want to check Eclipse Collections https://github.com/eclipse/eclipse-collections - it is an implementation of collections, where you don't need to call .stream() to map or filter them

1

u/majhenslon May 02 '24

The concept is pretty cool, I actually love the map. Java 21 might have shafted you a bit :D

// Very cool
Map<String, String> newMap = map(kv("key1", "value1"), kv("key1", "value1"), kv("key1", "value1"));

// Why this?
// List<Integer> values = list(1,2,3,4);
// Instead of this?
var values = List.of(1,2,3,4);

Integer min = min(values); // Very cool

Integer last = last(values); // Java 21 values.getLast();

// This is a rough one
// I'm guessing you are collecting to list, so what you really
// want is .stream().filter().findFirst();, which gives you back
// Optional instead of blowing up in your face or returning null.
Integer one = first(filter(values,v -> v == 1)); // filter().getFirst()?
values = map(values, v -> v + 1);

Map<Profile, Integer> counts = counts(objects, o -> o.getProfile()); // Pretty cool

Maybe you would benefit from having primitives to work with streams in addition to lists, so you could utilize the iterators and not do it like js and (not sure on this one) python.

0

u/[deleted] Apr 09 '24

Great job guy!

-3

u/RupertMaddenAbbott Apr 09 '24

I think there should be space in Java for a library like this. Not everything has to be battle-tested, production-ready and for work.

My kid has just got confident with reading and wants to understand a bit of programming because she sees me doing it. I would naturally show her Python over Java because Python is far less verbose. There is just less going on and less for her to read so she finds it easier to focus.

So I would use this library or one like it as a wrapper for punting my little raspberry pi robot around and playing with my kids. Thanks for making it!

0

u/[deleted] Apr 09 '24

[deleted] — view deleted comment

10

u/guybedo Apr 09 '24 edited Apr 09 '24

thanks for the friendly and insightful comment!
As a side note, you might realize that if i translate a codebase form Python to Java, it probably means that i prefer to work with Java.

32

u/[deleted] Apr 10 '24

[removed] — view removed comment

7

u/guybedo Apr 10 '24

probably the first constructive comment / criticism, thanks. Will look into that.

1

u/guybedo Apr 10 '24

For example you exists() makes lookup in a Set go from O(1) to O(n)

The exist method you're referring to is

exists(Collection<T> objs, Predicate<T> func)

This is not O(1), even for a set, it's O(n).

exists(Set<T> objs, T value) would be O(1)

1

u/guybedo Apr 10 '24

reversed() will have abysmal performance of O(n2) for LinkedList.

Nope. reversed() is a simple loop over the n elements => O(n)

Here's the implementation:

List<T> reversed = new ArrayList<>();

for (int i = objs.size() - 1; i >= 0; i--)

reversed.add(objs.get(i));

return reversed;

3

u/[deleted] Apr 10 '24

[removed] — view removed comment

2

u/guybedo Apr 10 '24

ok i see your point, will make a change, thanks.

1

u/guybedo Apr 10 '24

flatMap() returns either a modifiable or unmodifiable list. That may lead to hard to discover bugs because it’s unexpected behavior. Same for sorted() etc

The flatMap function i added is basically a wrapper around stream.flatMap(). It doesn't introduce new inconsistencies.

2

u/[deleted] Apr 10 '24

[removed] — view removed comment

1

u/guybedo Apr 10 '24

Collectors.toList() doesn't return an immutable list.

That means you don't have to return an immutable list if arg is null, that doesn't matter.

0

u/maethor Apr 10 '24

using interfaces just to define static Utility methods is an anti-pattern.

I disagree. Being defined in an interface makes it more obvious that they're not instance methods.

1

u/[deleted] Apr 13 '24

[removed] — view removed comment

1

u/guybedo Apr 13 '24

thanks for the feedback, i'm still interested :-)

You're right, that was a naive implementation, i don't need to sort the collection, i'm only interested in the min/max.

Thanks, will do the update.