Skip to content

Conversation

@ArtyomLobanov
Copy link
Owner

No description provided.

Copy link

@sproshev sproshev left a 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) {

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));
}
}

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));

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);
}
}

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;

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);
}
}

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

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);

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);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не проверяется ленивость

@sproshev
Copy link

10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants