Skip to content

Conversation

@MikePuzanov
Copy link
Owner

No description provided.

{
public static class Functions<T>
{
public static List<T> Map(List<T> list, Func<T, T> function)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не обязательно тип параметра должен совпадать с типом результата. Functions.Map(list, x => x.ToString()) тоже можно и часто используется.


namespace hw6MapFilterFold
{
public static class Functions<T>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Параметр-тип самому классу не нужен, у каждого метода есть свои

{
public static List<T> Map(List<T> list, Func<T, T> function)
{
int count = list.Count;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не понадобилось вроде :)

return resultList;
}

public static List<T> Filter(List<T> list, Func<T, bool> function)
Copy link
Collaborator

Choose a reason for hiding this comment

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

И надо комментарии ко всему

return returnList;
}

public static T Fold(List<T> list, T startValue,Func<T, T, T> function)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Тут тоже с типами всё сложнее :)

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

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

👍

public void FilterTest()
{
var resultList1 = new List<int>() { 2 };
var list1 = Functions.Filter(listInt, y => y % 2 == 0 );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var list1 = Functions.Filter(listInt, y => y % 2 == 0 );
var list1 = Functions.Filter(listInt, y => y % 2 == 0 );

/// <param name="startValue">начальное значение</param>
/// <param name="function">функция</param>
/// <returns>накопленное значение</returns>
public static TResult Fold<TValue, TResult>(List<TValue> list, TResult startValue,Func<TResult, TValue, TResult> function)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public static TResult Fold<TValue, TResult>(List<TValue> list, TResult startValue,Func<TResult, TValue, TResult> function)
public static TResult Fold<TValue, TResult>(List<TValue> list, TResult startValue, Func<TResult, TValue, TResult> function)

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