Skip to content

Useful Tuple type matches #9212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
nicolasstucki opened this issue Jun 20, 2020 · 6 comments
Closed
3 tasks done

Useful Tuple type matches #9212

nicolasstucki opened this issue Jun 20, 2020 · 6 comments

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jun 20, 2020

We already have a type match Tuple.Map.

We could also have:

We can take inspiration for the type matches we already have in Tuple. For example Size is just a fold.

@nicolasstucki
Copy link
Contributor Author

Fold prototype:

type Fold[Z, F[_, _], T <: Tuple] = T match
  case EmptyTuple => Z
  case h *: t => F[h, Fold[Z, t]]

type Size[T <: Tuple] = Fold[0, [X, Y] => S[X], T]

@nicolasstucki
Copy link
Contributor Author

FlatMap prototype :

  type FlatMap[Tup <: Tuple, F[_]] <: Tuple = Tup match
    case EmptyTuple => EmptyTuple
    case h *: t => F[h] ++ FlatMap[t, F]

@nicolasstucki
Copy link
Contributor Author

Not sure how the predicate of a Filter should look like. It could be a type P[_] that returns the type true or the type false.

@nicolasstucki
Copy link
Contributor Author

Does anyone have other suggestions for the Filter?

@julienrf
Copy link
Contributor

Not sure how the predicate of a Filter should look like. It could be a type P[_] that returns the type true or the type false.

That sounds reasonable. How could we filter all the elements of a tuple that have type Foo with such a predicate type?

[X] => X match { case Foo => true case _ => false }

?

@anatoliykmetyuk
Copy link
Contributor

I came up with the following implementation of the Filter type: #9235.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants