Exemplo n.º 1
0
 public static Config.Parser <B> flatMapTry <A, B>(
     this Config.Parser <A> aParser, Fn <ConfigPath, A, B> f
     ) =>
 (path, o) => aParser(path, o).flatMapRight(a => {
     try { return(new Either <ConfigLookupError, B>(f(path, a))); }
     catch (ConfigFetchException e) { return(new Either <ConfigLookupError, B>(e.error)); }
 });
Exemplo n.º 2
0
 public static Config.Parser <Tpl <A1, A2, A3, A4> > and <A1, A2, A3, A4>(
     this Config.Parser <A1> a1p, Config.Parser <A2> a2p, Config.Parser <A3> a3p, Config.Parser <A4> a4p
     ) =>
 (path, node) => {
     var a1E = a1p(path, node);
     if (a1E.isLeft)
     {
         return(a1E.__unsafeCastRight <Tpl <A1, A2, A3, A4> >());
     }
     var a2E = a2p(path, node);
     if (a2E.isLeft)
     {
         return(a2E.__unsafeCastRight <Tpl <A1, A2, A3, A4> >());
     }
     var a3E = a3p(path, node);
     if (a3E.isLeft)
     {
         return(a3E.__unsafeCastRight <Tpl <A1, A2, A3, A4> >());
     }
     var a4E = a4p(path, node);
     if (a4E.isLeft)
     {
         return(a4E.__unsafeCastRight <Tpl <A1, A2, A3, A4> >());
     }
     return(new Either <ConfigLookupError, Tpl <A1, A2, A3, A4> >(F.t(
                                                                      a1E.__unsafeGetRight, a2E.__unsafeGetRight, a3E.__unsafeGetRight, a4E.__unsafeGetRight
                                                                      )));
 };
Exemplo n.º 3
0
 public static Config.Parser <From, B> and <From, A1, A2, A3, A4, B>(
     this Config.Parser <From, A1> a1p, Config.Parser <From, A2> a2p, Config.Parser <From, A3> a3p,
     Config.Parser <From, A4> a4p, Func <A1, A2, A3, A4, B> f
     ) =>
 (path, node) => {
     var a1E = a1p(path, node);
     if (a1E.isLeft)
     {
         return(a1E.__unsafeCastRight <B>());
     }
     var a2E = a2p(path, node);
     if (a2E.isLeft)
     {
         return(a2E.__unsafeCastRight <B>());
     }
     var a3E = a3p(path, node);
     if (a3E.isLeft)
     {
         return(a3E.__unsafeCastRight <B>());
     }
     var a4E = a4p(path, node);
     if (a4E.isLeft)
     {
         return(a4E.__unsafeCastRight <B>());
     }
     return(f(a1E.__unsafeGetRight, a2E.__unsafeGetRight, a3E.__unsafeGetRight, a4E.__unsafeGetRight));
 };
Exemplo n.º 4
0
 /// <see cref="Config.tpl{From,R}"/>
 public static Config.Parser <From, C> tpl <From, A1, A2, A3, A4, C>(
     this Config.Parser <From, A1> a1p, Config.Parser <From, A2> a2p, Config.Parser <From, A3> a3p,
     Config.Parser <From, A4> a4p, Func <A1, A2, A3, A4, C> mapper
     ) =>
 (path, node) => {
     if (node is List <From> list)
     {
         if (list.Count == 4)
         {
             return
                 (from a1 in a1p(path.indexed(0), list[0])
                  from a2 in a2p(path.indexed(1), list[1])
                  from a3 in a3p(path.indexed(2), list[2])
                  from a4 in a4p(path.indexed(3), list[3])
                  select mapper(a1, a2, a3, a4));
         }
         else
         {
             return(Config.parseErrorFor <(A1, A2, A3, A4)>(
                        path, node, $"expected list of 4, got {list}"
                        ));
         }
     }
     else
     {
         return(Config.parseErrorFor <(A1, A2, A3, A4)>(path, node));
     }
 };
Exemplo n.º 5
0
 public static Config.Parser <From, A> or <From, A>(
     this Config.Parser <From, A> a1, Config.Parser <From, A> a2
     ) =>
 (path, node) => {
     var a1E = a1(path, node);
     return(a1E.isRight ? a1E : a2(path, node));
 };
Exemplo n.º 6
0
 public static Config.Parser <From, B> flatMap <From, A, B>(
     this Config.Parser <From, A> aParser, Func <ConfigPath, A, Option <B> > f
     ) => aParser.flatMap((path, a) => {
     var bOpt = f(path, a);
     return(bOpt.isSome
 ? Either <ConfigLookupError, B> .Right(bOpt.__unsafeGet)
 : Config.parseErrorEFor <B>(path, a));
 });
Exemplo n.º 7
0
 public static Config.Parser <B> flatMap <A, B>(
     this Config.Parser <A> aParser, Fn <ConfigPath, A, Option <B> > f
     ) => aParser.flatMap((path, a) => {
     var bOpt = f(path, a);
     return(bOpt.isDefined
 ? Either <ConfigLookupError, B> .Right(bOpt.get)
 : Config.parseErrorEFor <B>(path, a));
 });
Exemplo n.º 8
0
 public static Config.Parser <From, A> filter <From, A>(
     this Config.Parser <From, A> parser, Func <A, bool> predicate
     ) =>
 (path, o) => parser(path, o).flatMapRight(a =>
                                           predicate(a)
 ? new Either <ConfigLookupError, A>(a)
 : Config.parseErrorEFor <A>(path, a, "didn't pass predicate")
                                           );
Exemplo n.º 9
0
 public static Config.Parser <B> collect <A, B>(
     this Config.Parser <A> parser, Fn <A, Option <B> > collector
     ) =>
 (path, o) => parser(path, o).flatMapRight(a => {
     var bOpt = collector(a);
     return(bOpt.isDefined
   ? new Either <ConfigLookupError, B>(bOpt.get)
   : Config.parseErrorEFor <B>(path, a, "didn't pass collector"));
 });
Exemplo n.º 10
0
 public static Config.Parser <From, B> collect <From, A, B>(
     this Config.Parser <From, A> parser, Func <A, Option <B> > collector
     ) =>
 (path, o) => parser(path, o).flatMapRight(a => {
     var bOpt = collector(a);
     return(bOpt.isSome
   ? new Either <ConfigLookupError, B>(bOpt.__unsafeGet)
   : Config.parseErrorEFor <B>(path, a, "didn't pass collector"));
 });
Exemplo n.º 11
0
 public static Config.Parser <From, C> tpl <From, A1, A2, C>(
     this Config.Parser <From, A1> a1p, Config.Parser <From, A2> a2p, Func <A1, A2, C> mapper
     ) =>
 (path, node) => {
     if (node is List <From> list)
     {
         if (list.Count == 2)
         {
             return
                 (from a1 in a1p(path.indexed(0), list[0])
                  from a2 in a2p(path.indexed(1), list[1])
                  select mapper(a1, a2));
         }
         else
         {
             return(Config.parseErrorFor <(A1, A2)>(path, node, $"expected list of 2, got {list}"));
         }
     }
     else
     {
         return(Config.parseErrorFor <(A1, A2)>(path, node));
     }
 };
Exemplo n.º 12
0
 public abstract Either <ConfigFetchError, IList <A> > eitherList <A>(string key, Config.Parser <A> parser);
Exemplo n.º 13
0
 public static Config.Parser <From, B> map <From, A, B>(
     this Config.Parser <From, A> aParser, Func <A, B> f
     ) =>
 aParser.map((path, a) => f(a));
Exemplo n.º 14
0
 public static Config.Parser <From, B> flatMap <From, A, B>(
     this Config.Parser <From, A> aParser, Func <ConfigPath, A, Either <ConfigLookupError, B> > f
     ) =>
 (path, o) => aParser(path, o).flatMapRight(a => f(path, a));
Exemplo n.º 15
0
 public IList <A> getList <A>(string key, Config.Parser <A> parser)
 {
     return(tryList(key, parser).getOrThrow);
 }
Exemplo n.º 16
0
 public static Config.Parser <From, B> flatMap <From, A, B>(
     this Config.Parser <From, A> aParser, Func <A, Option <B> > f
     ) => aParser.flatMap((path, a) => f(a));
Exemplo n.º 17
0
 public static Config.Parser <From, B> flatMapParser <From, A, B>(
     this Config.Parser <From, A> aParser, Func <ConfigPath, A, Config.Parser <A, B> > bParser
     ) => (path, node) => aParser(path, node).flatMapRight(a => bParser(path, a)(path, a));
Exemplo n.º 18
0
 public static Either <ConfigLookupError, To> aE <From, To>(
     this Config.Parser <From, To> p, Config.ParserInput <From> input
     ) => p(input.path, input.node);
Exemplo n.º 19
0
 public static To a <From, To>(
     this Config.Parser <From, To> p, Config.ParserInput <From> input
     ) => p(input.path, input.node).rightOrThrow;
Exemplo n.º 20
0
 public static Config.Parser <B> map <A, B>(this Config.Parser <A> aParser, Fn <ConfigPath, A, B> f) =>
 (path, o) => aParser(path, o).mapRight(a => f(path, a));
Exemplo n.º 21
0
 public static Config.Parser <B> map <A, B>(this Config.Parser <A> aParser, Fn <A, B> f) =>
 aParser.map((path, a) => f(a));
Exemplo n.º 22
0
 public Try <IList <A> > tryList <A>(string key, Config.Parser <A> parser)
 {
     return(eitherList(key, parser).fold(tryEx <IList <A> >, F.scs));
 }
Exemplo n.º 23
0
 public static Config.Parser <From, B> map <From, A, B>(
     this Config.Parser <From, A> aParser, Func <ConfigPath, A, B> f
     ) =>
 (path, o) => aParser(path, o).mapRight(a => f(path, a));
Exemplo n.º 24
0
 public static Config.Parser <B> flatMap <A, B>(
     this Config.Parser <A> aParser, Fn <A, Option <B> > f
     ) => aParser.flatMap((path, a) => f(a));
Exemplo n.º 25
0
 public static Either <ConfigLookupError, A> testParser <A>(
     this string json, Config.Parser <object, A> parser
     ) =>
 $@"{{""item"": {json}}}".asConfig().eitherGet("item", parser);
Exemplo n.º 26
0
 public Option <IList <A> > optList <A>(string key, Config.Parser <A> parser)
 {
     return(eitherList(key, parser).toOpt());
 }