Skip to content

Instantly share code, notes, and snippets.

@dance2die

dance2die/ParseFP.cs

Created Oct 28, 2017
Embed
What would you like to do?
Parse functionally.
public static int[] Parse(string data)
{
var result = new List<int>();
var commands = new Dictionary<char, Func<int, int>>
{
{'i', n => ++n },
{'d', n => --n },
{'s', n => n * n },
{'o', n => { result.Add(n); return n; } }
};
var value = 0;
data.Select(c => value = commands[c](value)).ToList();
return result.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.