Skip to content
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

Revenge of the Splat #12

Open
adam-rocska opened this issue Nov 7, 2023 · 1 comment
Open

Revenge of the Splat #12

adam-rocska opened this issue Nov 7, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@adam-rocska
Copy link
Member

Swift had tuple Splatting, which was awesome.
Now we don't have it, which sux.

I've been missing it for years now as I have it on my standard toolbelt / programming logic coming from different languages.

I have no clue who this genius is on Swift Forums, but this comment gave me the idea below:

import Foundation

infix operator |> : MultiplicationPrecedence
func |> <Input, Output>(
  input: Input,
  lambda: (Input) -> Output
) -> Output { lambda(input) }

func call<Args, Result>(with args: Args, function: (Args) -> Result) -> Result {
  function(args)
}

func add(_ a: Int, _ b: Int) -> Int { a + b }
// this still compiles today
let input = (40, 2)
print(call(with: input, function: add))

print(input |> add)
@adam-rocska adam-rocska added the enhancement New feature or request label Nov 7, 2023
@adam-rocska
Copy link
Member Author

Postponed until the new swift generic tuple expansion black magic is convincingly stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant