How does str.startswith really work?

There is technically no reason to accept other sequence types, no. The source code roughly does this: if isinstance(prefix, tuple): for substring in prefix: if not isinstance(substring, str): raise TypeError(…) return tailmatch(…) elif not isinstance(prefix, str): raise TypeError(…) return tailmatch(…) (where tailmatch(…) does the actual matching work). So yes, any iterable would do for that … Read more

In C# 7 is it possible to deconstruct tuples as method arguments

You can shorten it to: void test( Action<ValueTuple<string, int>> fn) { fn((“hello”, 10)); } test(((string s, int i) t) => { Console.WriteLine(t.s); Console.WriteLine(t.i); }); Hopefully, one day we might be able to splat the parameters from a tuple to the method invocation: void test(Action<ValueTuple<string, int>> fn) { fn(@(“hello”, 10)); // <– made up syntax } … Read more

std::tuple get() member function

From C++0x draft: [ Note: The reason get is a nonmember function is that if this functionality had been provided as a member function, code where the type depended on a template parameter would have required using the template keyword. — end note ] This can be illustrated with this code: template <typename T> struct … Read more