In Swift 4, how can I curry func
, or something similar:
func doSomething(a: A, b: B, c: C) {
}
let do_a = doSomething(a: value_a)
let do_ab = do_a(b: value_b)
let result = do_ab(c: value_c)
In JS, we can do:
const sum = x => y => x + y;
// returns a function y => 2 + y
sum (2);
// returns the number 3
sum (2)(1);
I read the answer in here Curry Function in Swift
But I want to ask for the current Swift (Swift 4). And can I avoid to create a generic func?
func curry<A,B,C,D,E>(f: (A, B, C, D) -> E) -> A -> B -> C -> D -> E
This post is very useful: https://robots.thoughtbot.com/introduction-to-function-currying-in-swift
But it's from 2014
Thank you.