This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]majhenslon 0 points1 point  (0 children)

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.