예제 #1
0
파일: Pattern.cs 프로젝트: toddcoder/Kagami
        public bool Match(IObject comparisand, Hash <string, IObject> bindings)
        {
            lambda.CopyFields(fields);
            var result = lambda.Invoke(comparisand);

            switch (result)
            {
            case Boolean boolean when arguments.Length == 0:
                return(boolean.Value);

            case Boolean boolean when arguments.Length == 1:
                return(match(boolean, arguments[0], bindings));

            case Some some when arguments.Length == 1:
                return(match(some.Value, arguments[0], bindings));

            default:
                if (result is Some {
                    Value : Tuple tuple
                } && tuple.Length.Value == arguments.Length)
                {
                    return(tuple.Value.Zip(arguments, (l, r) => match(l, r, bindings)).All(b => b));
                }

                break;
            }