Skip to content

Готовая задача с генериками - #12

Open
Palezehvat wants to merge 2 commits into
masterfrom
FilterFoldMap
Open

Palezehvat wants to merge 2 commits into
masterfrom
FilterFoldMap

Conversation

@Palezehvat

Copy link
Copy Markdown
Owner

Задача на filter fold map

Comment thread FilterFoldMap/FilterFoldMap/Program.cs Outdated

class Program
{
public static void Main()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это не нужно, уберите :)

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Все три функции на самом деле должны быть в одном классе, а у Вас аж три отдельных (!) проекта с тестами. Упростите структуру решения, пожалуйста :)

Comment thread FilterFoldMap/FilterFoldMap/Filter.cs Outdated
/// <summary>
/// Implements the filter function
/// </summary>
public class FilterList

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут и ниже не хватает static-ов, потому как у класса нет своего состояния.

Comment thread FilterFoldMap/FilterFoldMap/Filter.cs Outdated
{
if (list == null)
{
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А нельзя так. Кидайте исключение

Comment thread FilterFoldMap/FilterFoldMap/Filter.cs Outdated
{
return null;
}
List<TypeOfValue> newList = new List<TypeOfValue>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
List<TypeOfValue> newList = new List<TypeOfValue>();
List<TypeOfValue> newList = new();

Comment thread FilterFoldMap/FilterFoldMap/Fold.cs Outdated
/// <param name="accumulatedValue">Cumulative value with the selected type</param>
/// <param name="function">A function for accumulating a value, takes an accumulating value and a list item</param>
/// <returns>Accumulated value</returns>
public TypeOfValue Fold<TypeOfValue>(List<TypeOfValue> list, TypeOfValue accumulatedValue, Func<TypeOfValue, TypeOfValue, TypeOfValue> function)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно более общий тип, потому что тип результата не обязан совпадать с типом значений в списке

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