nessos / Eff

A library design for programming with effects and handlers in C#
MIT License
128 stars 13 forks source link

Pattern Matching on Eff type #2

Closed solvingj closed 6 years ago

solvingj commented 6 years ago

Can you please provide an explanation as to how this bit of code works? It's unclear to me how the Eff gets matched to the "Set..." types like SetException.

https://github.com/nessos/Eff/blob/master/src/Eff.Core/EffExecutor.cs#L30

public static async Task<TResult> Run<TResult>(this Eff<TResult> eff, IEffectHandler handler)
        {
            ...
            var result = default(TResult);
            var done = false;
            while (!done)
            {
                switch (eff)
                {
                    case SetException<TResult> setException:
                        await handler.Handle(setException);
                        break;