How to pass Predicate to a Coroutine?

I’m trying to send a bool function as a parameter in a coroutine and i learned that using predicate is the solution to send bools (i think?..) however I’m unable to get it working because I’m not understanding what the “object” parameter is. It isn’t the class?

 IEnumerator Pause( Predicate<WhatsThisParameter?> condition )
    {
        while (!condition)
        {
            yield return null;
        }       
    }

The generic Predicate type is a special delegate type that always returns a boolean and takes a single generic parameter. If you just want a delegate that takes no parameter at all you should simply use System.Func<bool> instead.

Also a delegate is a “method pointer” so you have to actually execute it to get the return value

IEnumerator PauseWhile( System.Func<bool> condition )
{
    if (condition == null)
        yield break;
    while (!condition())
        yield return null;
}

This can be used like this:

yield return StartCoroutine(PauseWhile(()=>YourConditionHere));

A Predicate always takes a parameter. For example:

Predicate<int> condition = (p) => p > 10

if(condition(5))  // returns "false"

if(condition(11)) // returns "true"

The type Predicate<int> would be equivalent to the type Func<int, bool>. So it’s a delegate to a method that takes an int parameter and returns a bool.

Keep in mind that you can assign any kind of method that matches the delegate signature, not only anonymous methods / lambda expressions:

private bool Test(int aParam)
{
    return aParam == 3;
}

Predicate<int> condition = Test;

condition(3) // --> returns "true"