The code you've written actually works fine as long as you are using System.Linq
. However, if you want to create a non-empty map, your key class (X
) has to derive from Record<T>
as well, like this:
using System;
using System.Linq;
using LanguageExt;
using static LanguageExt.Prelude;
public class X : Record<X>
{
public string a;
public string b;
public static X Create(string a, string b)
=> new X() { a = a, b = b };
}
public class Y
{
public string c;
public static Y Create(string c)
=> new Y() { c = c };
}
class Program
{
static void Main(string[] args)
{
var myMap =
Map(
(X.Create("a1", "b1"), Y.Create("c1")),
(X.Create("a2", "b2"), Y.Create("c2")));
foreach (var str in myMap.Keys.Select(_ => _.a))
{
Console.WriteLine(str);
}
}
}
Output is:
a1
a2