/// <summary>Test if the start of current tuple is equal to another tuple</summary> /// <param name="left">Larger tuple</param> /// <param name="right">Smaller tuple</param> /// <returns>True if the beginning of <paramref name="left"/> is equal to <paramref name="right"/> or if both tuples are identical</returns> public static bool StartsWith([NotNull] this ITuple left, [NotNull] ITuple right) { if (left == null) { throw new ArgumentNullException(nameof(left)); } if (right == null) { throw new ArgumentNullException(nameof(right)); } //REVIEW: move this on ITuple interface ? return(STuple.StartsWith(left, right)); }
/// <summary>Create a formatter that just add or remove a prefix to values</summary> public static ITupleFormatter <T> CreateAppender(ITuple prefix) { if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } return(new AnonymousTupleFormatter <T>( (value) => prefix.Append <T>(value), (tuple) => { if (tuple.Count != prefix.Count + 1) { throw new ArgumentException("Tuple size is invalid", nameof(tuple)); } if (!STuple.StartsWith(tuple, prefix)) { throw new ArgumentException("Tuple does not start with the expected prefix", nameof(tuple)); } return tuple.Last <T>(); } )); }