On Dec 7, 2019, at 07:33, Wes Turner <wes.turner@gmail.com> wrote:
+1 for itertools.first(seq, default=Exception) *and* itertools.one(seq, default=Exception)
What does default=Exception mean? What happens if you pass a different value? Does it do one thing if the argument is a type that’s a subclass of Exception (or of BaseException?) and a different thing if it’s any other value? Also, why do you want these to be different from similar recipes like nth and first_true, and from the versions of exactly these functions in more_itertools, and the other related ones like only? Also, “seq” implies that you’re expecting these to be used on sequences, not general iterables. In that case, why not just use [0]? Arguably, first, and maybe some of it’s cousins, should go into the recipes. And I don’t see any reason they shouldn’t be identical to the versions in more-itertools, but if there is one, it should be coordinated with Erik Rose in some way so they stay in sync. Maybe first is so useful, so much more so than all of the other very useful recipes, including things like consume, flatten, and unique (which IIRC were the ones that convinced everyone it’s time to add a more-itertools link to the docs), that it needs to be slightly more discoverable—e.g., by itertools.<TAB> completion? But that seems unlikely given that they’ve been recipes for decades and first wasn’t. And it seems even less likely for one, which nobody has mentioned in this thread yet. If there’s a general argument that linking to more-itertools hasn’t helped anything, or that the recipes are still useless until someone makes the often-proposed/never-followed-through change of finding a way to make the recipes individually searchable and linkable, or whatever, that’s fine, but it’s not really an argument against making a special case for one that isn’t made for unique or consume.