-
Notifications
You must be signed in to change notification settings - Fork 0
Java02. ДЗ 03, Лобанов Артём #6
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
base: master
Are you sure you want to change the base?
Conversation
sproshev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
надо исправлять
| import java.util.LinkedList; | ||
|
|
||
| public final class Collections { | ||
| public static <X, Y> Iterable<Y> map(Iterable<X> stream, Function1<? super X, Y> f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
надо стараться принимать как можно более общий параметр и возращать как можно более конкретный результат. Т.е. в данном случае желательно вернуть List или LinkedList
| public default <Z> Function1<X, Z> compose(Function1<? super Y, ? extends Z> g) { | ||
| return x -> g.apply(Function1.this.apply(x)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все методы и поля внутри интерфейса по умолчанию public, поэтому этот модификатор указывать не надо
| public Y apply(X x); | ||
|
|
||
| public default <Z> Function1<X, Z> compose(Function1<? super Y, ? extends Z> g) { | ||
| return x -> g.apply(Function1.this.apply(x)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x -> g.apply(apply(x))
| public default Function2<X2, X1, Y> flip() { | ||
| return (x2, x1) -> Function2.this.apply(x1, x2); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function2.this. излишен
|
|
||
| public interface Predicate<X> extends Function1<X, Boolean> { | ||
| Predicate ALWAYS_TRUE = x -> true; | ||
| Predicate ALWAYS_FALSE = x -> false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Predicate<Object> или Predicate<?>
| public default Predicate<X> not() { | ||
| return x -> !Predicate.this.apply(x); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
| assertEquals("(1 + (2 + (3 + (4 + (5 + 0)))))", Collections.foldr(f, "0", Arrays.asList(1, 2, 3, 4, 5))); | ||
| } | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не проверяются wildcard'ы
| import static ru.spbau.lobanov.functional.PredicateTest.checkContents; | ||
|
|
||
| public class CollectionsTest { | ||
| private static final Iterable<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caps
| import static org.junit.Assert.*; | ||
|
|
||
| public class PredicateTest { | ||
| private static final Iterable<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caps
| return !iterator.hasNext(); | ||
| } | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не проверяется ленивость
|
10 |
No description provided.