swift - How can I return a function that depends on two functions? -


i have following function:

private func getfunctiontoplot() -> ((double) -> double) {     var function: (double) -> double = sin + cos     return function  } 

i return function takes double , returns double, functions should sin + cos. both sin , cos independently take double , return double, how can return sin($0) + cos($0).

your question little broad, line claim doesn't compile does compile; there's nothing wrong you're doing. problem code incomplete. here test example is complete:

private func getfunctiontoplot() -> ((double) -> double) {     var function: (double) -> double     function = {_ in return 2.0}     return function } 

edit revised question, here's test example of sort of thing seem trying do:

func sin(_ d:double) -> double {return 1} func cos(_ d:double) -> double {return 1} private func getfunctiontoplot() -> ((double) -> double) {     let f1: (double) -> double = sin     let f2: (double) -> double = cos     return {f1(f2($0))} // or maybe f1($0) + f2($0) } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -