From bfd0c8a6db0ef1237a2e45f7f995c27961f257ee Mon Sep 17 00:00:00 2001 From: fawdlstty Date: Tue, 14 Dec 2021 00:25:29 +0800 Subject: [PATCH] 1 --- fa/fac/Info.cs | 10 +++++++--- src/fa/Error.fa | 4 ++++ src/fa/Optional | 0 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/fa/Error.fa create mode 100644 src/fa/Optional diff --git a/fa/fac/Info.cs b/fa/fac/Info.cs index 5399c96..5b42025 100644 --- a/fa/fac/Info.cs +++ b/fa/fac/Info.cs @@ -201,10 +201,14 @@ public static string GenerateCSharp () { _sb.AppendLine (" public string GetError () => err;"); _sb.AppendLine (" public static Optional FromValue (T _t) => new Optional { t = _t };"); _sb.AppendLine (" public static Optional FromError (string _err) => new Optional { err = _err };"); - //_sb.AppendLine (" public static T operator | (Optional t1, T t2) => t1.HasValue () ? t1.GetValue () : t2; // operator ??"); - //_sb.AppendLine (" public static Optional operator | (Optional t1, Optional t2) => t1.HasValue () ? t1 : t2; // operator ??"); - // FIXME: 支持“?? 异常”用法,但传字符串不对,假如出现 string? 类型的 ?? 就尴尬了 _sb.AppendLine ("}"); + //_sb.AppendLine ("public class OptionalVoid {"); + //_sb.AppendLine (" public string err = \"\";"); + //_sb.AppendLine (" public bool HasValue () => err == \"\";"); + //_sb.AppendLine (" public string GetError () => err;"); + //_sb.AppendLine (" public static OptionalVoid FromValue () => new OptionalVoid {};"); + //_sb.AppendLine (" public static OptionalVoid FromError (string _err) => new OptionalVoid { err = _err };"); + //_sb.AppendLine ("}"); _sb.AppendLine ("}"); _sb.AppendLine (); _sb.AppendLine (); diff --git a/src/fa/Error.fa b/src/fa/Error.fa new file mode 100644 index 0000000..c6575e0 --- /dev/null +++ b/src/fa/Error.fa @@ -0,0 +1,4 @@ +public enum Error { + DivideZero, + IndexOutOfBounds, +} diff --git a/src/fa/Optional b/src/fa/Optional new file mode 100644 index 0000000..e69de29