CommandLine.Core.SpecificationPropertyRules.EnforceRequired C# (CSharp) Method

EnforceRequired() private static method

private static EnforceRequired ( ) : IEnumerable>>.Func
return IEnumerable>>.Func
        private static Func<IEnumerable<SpecificationProperty>, IEnumerable<Maybe<Error>>> EnforceRequired()
        {
            return specProps =>
            {
                List<string> setsWithTrue =
                    specProps.Where(sp => sp.Specification.IsOption() && sp.Value.IsJust() && sp.Specification.Required)
                        .Select(x => ((OptionSpecification)x.Specification).SetName).ToList();
                
                var requiredButEmpty =
                    specProps.Where(sp => sp.Value.IsNothing() && 
                                          sp.Specification.Required &&
                                          !setsWithTrue.Contains(((OptionSpecification)sp.Specification).SetName)).ToList();
                    if (requiredButEmpty.Any()) {
                        return requiredButEmpty.Select(s => Maybe.Just<Error>(new MissingRequiredOptionError(
                            NameInfo.FromSpecification(s.Specification))));
                    }
                    return Enumerable.Empty<Nothing<Error>>();
                };
        }