Skip to content

Instantly share code, notes, and snippets.

@emanuelefirmani
Created September 16, 2018 13:34
Show Gist options
  • Save emanuelefirmani/e378c4bceb37bc1cbd25f38e516911d6 to your computer and use it in GitHub Desktop.
Save emanuelefirmani/e378c4bceb37bc1cbd25f38e516911d6 to your computer and use it in GitHub Desktop.
private IEnumerable<string> FormatNonFunctional(List<string> shoppingList)
{
var index = 0;
var result = new List<string>();
_outp.WriteLine(shoppingList.Count.ToString());
return shoppingList.Select(item => (index++).ToString() + item.Capitalize());
}
@emanuelefirmani
Copy link
Author

@arialdomartini, does it solve?

@emanuelefirmani
Copy link
Author

The body of the lambda expression can be replaced by:
item.Capitalize().PrependNumeration(index++)

@emanuelefirmani
Copy link
Author

Even better:

private IEnumerable<string> FormatFunctional(List<string> shoppingList, int startingIndex = 0)
    => shoppingList.Select(item => shoppingList.Select(item => item.Capitalize().PrependNumeration(startingIndex++)).ToList();

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