-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide version of AbstractStreamEx#indexOf which returns int #161
Comments
Please show a complete use-case where you want to use such method. Note that as static <T> Function<StreamEx<T>, Integer> indexOf(T t) {
return s -> (int)(s.indexOf(t).orElse(-1));
} And use it like this: int idx = streamEx.chain(indexOf("foo")); |
See my changes in AbstractProjectNode. I need to cast the result to You're right, it's indeed not that simple to invent a name for this new method. I don't think it's number of characters that matters, it's better to have readable and comprehensible code even if it's (slightly) longer. And I think that something like If we decide that the current version is not convenient and deprecate it, we can use a simpler name for the new method, there will be no need to mention |
You actually don't need an index, you need a prefix. How about this? commonGroupsPath = StreamEx.of(commonGroupsPath).zipWith(path.stream())
.takeWhile(e -> e.getKey().equals(e.getValue())).keys().toList(); (Unlike In general indices are rarely necessary. Sometimes they are just used as crutches because API does not allow you to get the result without them, but the final result does not include indices. Btw I have ModuleGrouper grouper = ModuleGrouper.instanceFor(myProject);
Set<ModuleDescription> nonGroupedModules = StreamEx.of(modules)
.filter(md -> grouper.getGroupPath(md).isEmpty()).toCollection(LinkedHashSet::new);
Set<String> topLevelGroups = StreamEx.of(modules).map(grouper::getGroupPath)
.remove(List::isEmpty).map(path -> path.get(0)).toCollection(LinkedHashSet::new);
List<String> commonGroupsPath = StreamEx.of(modules).map(grouper::getGroupPath)
.collect(MoreCollectors.commonListPrefix()); |
It's inconvenient to cast result of
indexOf
from long to int. I think developers usually work with streams which contains less than 2^31 elements. So it would be great to have a variant of this method which returnsOptionalInt
or evenint
asList::indexOf
does.The text was updated successfully, but these errors were encountered: