spebbe / dartz

Functional programming in Dart
MIT License
749 stars 60 forks source link

Add Tuple Functions #89

Closed cranst0n closed 2 years ago

cranst0n commented 2 years ago

I think it would be useful to add the following functions to the TupleN classes:

I've implemented these for few of them using extensions but can open a PR for all of them implemented directly in the class if you would be willing to merge.

Here's a sample of what I've done thus far:

extension Tuple3Ops<A, B, C> on Tuple3<A, B, C> {
  A get head => value1;
  Tuple2<B, C> get tail => Tuple2(value2, value3);

  Tuple2<A, B> get init => Tuple2(value1, value2);
  C get last => value3;
}

The head/last would just be different names for existing functionality, so if you think it's unnecessary I would leave them out. Any other feedback would be welcome.

spebbe commented 2 years ago

Hi @cranst0n – sounds like a great addition that would bring us one step closer to https://github.com/milessabin/shapeless HLists! Your naming scheme looks good to me. Please open a PR if you are willing. Thank you!

cranst0n commented 2 years ago

Great! I'll submit something in the next few days.

spebbe commented 2 years ago

Merged and released in 0.10.1 – Thanks again!