/// <summary>
 /// Append the Some(x) of one option to the Some(y) of another.
 /// For numeric values the behaviour is to sum the Somes (lhs + rhs)
 /// For string values the behaviour is to concatenate the strings
 /// For Lst/Stck/Que values the behaviour is to concatenate the lists
 /// For Map or Set values the behaviour is to merge the sets
 /// Otherwise if the T type derives from IAppendable then the behaviour
 /// is to call lhs.Append(rhs);
 /// </summary>
 /// <param name="lhs">Left-hand side of the operation</param>
 /// <param name="rhs">Right-hand side of the operation</param>
 /// <returns>lhs + rhs</returns>
 public static T?append <T>(T?lhs, T?rhs) where T : struct
 {
     if (!lhs.HasValue && !rhs.HasValue)
     {
         return(lhs);                                 // None  + None  = None
     }
     if (!rhs.HasValue)
     {
         return(lhs);                                 // Value + None  = Value
     }
     if (!lhs.HasValue)
     {
         return(rhs);                                 // None  + Value = Value
     }
     return(TypeDesc.Append(lhs.Value, rhs.Value, TypeDesc <T> .Default));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Append the Some(x) of one option to the Some(y) of another.
 /// For numeric values the behaviour is to sum the Somes (lhs + rhs)
 /// For string values the behaviour is to concatenate the strings
 /// For Lst/Stck/Que values the behaviour is to concatenate the lists
 /// For Map or Set values the behaviour is to merge the sets
 /// Otherwise if the T type derives from IAppendable then the behaviour
 /// is to call lhs.Append(rhs);
 /// </summary>
 /// <param name="lhs">Left-hand side of the operation</param>
 /// <param name="rhs">Right-hand side of the operation</param>
 /// <returns>lhs + rhs</returns>
 public OptionUnsafe <T> Append(OptionUnsafe <T> rhs)
 {
     if (IsNone && rhs.IsNone)
     {
         return(this);                       // None  + None  = None
     }
     if (rhs.IsNone)
     {
         return(this);                       // Value + None  = Value
     }
     if (this.IsNone)
     {
         return(rhs);                        // None  + Value = Value
     }
     return(TypeDesc.Append(Value, rhs.Value, TypeDesc <T> .Default));
 }
Ejemplo n.º 3
0
 public NewType <T> Append(NewType <T> rhs) =>
 GetType() == rhs.GetType()
         ? (NewType <T>) NewType.Construct(GetType(), TypeDesc.Append(Value, rhs.Value, TypeDesc <T> .Default))
         : failwith <NewType <T> >("Mismatched NewTypes in append/add");