Skip to content

Java05. ДЗ 04, Кузиванов Николай#1

Open
Carups wants to merge 4 commits intomasterfrom
home
Open

Java05. ДЗ 04, Кузиванов Николай#1
Carups wants to merge 4 commits intomasterfrom
home

Conversation

@Carups
Copy link
Owner

@Carups Carups commented Apr 27, 2018

No description provided.


public abstract boolean run(T obj);

static public Predicate ALWAYS_TRUE = new Predicate() {
Copy link

Choose a reason for hiding this comment

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

generic?

}
};

static public Predicate ALWAYS_FALSE = new Predicate() {
Copy link

Choose a reason for hiding this comment

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

generic? надо написать так, чтобы оба предиката можно было использовать без warning'ов

assertEquals(out1, 45);
assertEquals(out2, -45);
}

Copy link

Choose a reason for hiding this comment

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

не проверяются ? extends ..., ? super ...

@Test
public void testRun() {
assertTrue(100 == sq.run(10));
assertTrue(100 == sq.run(-10));
Copy link

Choose a reason for hiding this comment

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

assertEquals

@Test
public void testCompose() {
Function1<Integer, Integer> tmp = sq.compose(inc);
assertTrue(5 == tmp.run(2));
Copy link

Choose a reason for hiding this comment

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

assertEquals

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.

8

public class Collections {

public static <A, R> Collection<R> map(Function1<? super A, ? extends R> func,
Collection<? extends A> input) {

Choose a reason for hiding this comment

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

цитирую:

Cоздать класс Collections со следующими статическими методами, оперирующими Iterable, Function1, Function2 и Predicate:

  • map — принимает f и a, применяет f к каждому элементу a_i и возвращает список [f(a_1), ..., f(a_n)]

и т.д.

public static <A, R> R foldr(Function2<? super A, ? super R, ? extends R> func,
Collection<? extends A> input,
R init) {
List<A> elem = new ArrayList<>();

Choose a reason for hiding this comment

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

см конструктор ArrayList

R init) {
List<A> elem = new ArrayList<>();
elem.addAll(input);
ListIterator<A> it = elem.listIterator();

Choose a reason for hiding this comment

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

см параметры метода listIterator

public void testRun(){
assertTrue(42 == magic.run(2.0, "asdf"));
assertTrue(5 == minus.run(2, -3));
assertTrue(5 == plus.run(2, 3));

Choose a reason for hiding this comment

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

assertEquals

assertEquals(true, even.run(2));
assertEquals(false, even.run(3));
assertEquals(true, one.run("a"));
assertEquals(false, one.run("abacaba"));

Choose a reason for hiding this comment

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

assertTrue/assertFalse

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.

2 participants