I have never been really good at C# and I am trying to better myself by learing new things. I am now trying lambda's.
this is my code so far:
public static Func<float[], bool[]> CategoricalMap(Func<float, bool> mapper)
{
Func<float[], bool[]> fun = x => new bool[] { true };
return fun;
}
public static void Main()
{
Func<float, bool> success = x => x == 5.5f;
var result = CategoricalMap(success)(new float[] { 4f, 5.5f, 3.5f, -5.5f, 10.2f });
Console.ReadKey();
}
What I am trying to do is, to check what number is equal to 5.5f, but I don't know how to get the floats to show up in the CategoricalMap function. I know a bit of the puzzle, I have to do this:
mapper(float);
but I don't know how to get the floats from result to the function. Please help.
Edit 1
I think I should make things more clear, A few weeks ago asked a someone to give me lambda challenges, sadly I have no way of contacting him. (kinda stupid of me) this is what he gave me:
Create the lambda success which returns true if the given value is above or equal to 5.5f
Create the following function:
CategoricalMap
Creates a mapper function
Input: mapper a function of type Func<float, bool>
Output: a function of type Func<float[], bool[]> that takes in an array of booleans and applies the function mapper to each of the elements and stores the results in an integer array
var matching = { 4f, 5.5f, 3.5f, ... }.Where(x => x == 5.5f);bool[] CategoricalMap(float someFloat, float[] floatArray)would suffice, wouldn't it?Select?resultto befalse, true, false, false, false? Hint: you need a loop.