Skip to content

Instantly share code, notes, and snippets.

@golf1052
Created January 23, 2022 10:47
Show Gist options
  • Save golf1052/064c59e036fb18a000364295ad6a1bc2 to your computer and use it in GitHub Desktop.
Save golf1052/064c59e036fb18a000364295ad6a1bc2 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
var mapResult = new string[] {"πŸ•", "πŸ•", "πŸ•", "πŸ•"}.Select(e => "🐢");
PrintEnumerable(mapResult);
var filterResult = new string[] {"πŸ•", "🐢", "πŸ•", "πŸ•"}.Where(e => e == "🐢");
PrintEnumerable(filterResult);
var everyResult = new string[] {"πŸ•", "πŸ•", "🐢", "πŸ•"}.All(e => e == "🐢");
Console.WriteLine(everyResult);
var someResult = new string[] {"πŸ•", "🐢", "🐢", "πŸ•"}.Any(e => e == "🐢");
Console.WriteLine(someResult);
var fillResult = new string[] {"πŸ•", "πŸ•", "πŸ•", "πŸ•"}.Select((e, i) => i > 0 ? "🐢" : e);
PrintEnumerable(fillResult);
var findIndexResult = new string[] {"πŸ•", "πŸ•", "🐢", "πŸ•"}.TakeWhile(e => e != "🐢").Count();
Console.WriteLine(findIndexResult);
var findResult = new string[] {"πŸ•", "🐢", "πŸ•", "πŸ•"}.First(e => e == "🐢");
Console.WriteLine(findResult);
var reduceResult = new string[] {"πŸ₯’", "πŸ…", "🍞", "πŸ§€"}.Aggregate((acc, cur) => $"{acc}{cur}"); // you can't actually turn these four emoji into πŸ”
Console.WriteLine(reduceResult);
}
public static void PrintEnumerable(IEnumerable<string> arr)
{
Console.WriteLine(string.Join("", arr));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment