Java02. ДЗ 03, Лобанов Артём#6
Open
ArtyomLobanov wants to merge 2 commits into
Open
Conversation
sproshev
suggested changes
Oct 30, 2016
| 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.
надо стараться принимать как можно более общий параметр и возращать как можно более конкретный результат. Т.е. в данном случае желательно вернуть 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.
все методы и поля внутри интерфейса по умолчанию 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)); |
| public default Function2<X2, X1, Y> flip() { | ||
| return (x2, x1) -> Function2.this.apply(x1, x2); | ||
| } | ||
| } |
|
|
||
| public interface Predicate<X> extends Function1<X, Boolean> { | ||
| Predicate ALWAYS_TRUE = x -> true; | ||
| Predicate ALWAYS_FALSE = x -> false; |
| public default Predicate<X> not() { | ||
| return x -> !Predicate.this.apply(x); | ||
| } | ||
| } |
| assertEquals("(1 + (2 + (3 + (4 + (5 + 0)))))", Collections.foldr(f, "0", Arrays.asList(1, 2, 3, 4, 5))); | ||
| } | ||
|
|
||
| } No newline at end of file |
| 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); |
| 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); |
| return !iterator.hasNext(); | ||
| } | ||
|
|
||
| } No newline at end of file |
|
10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.