So what I had to do was: ``` func MyFunction() : S...
# getting-started
z
So what I had to do was:
Copy code
func MyFunction() : String {
   var myReturnVariable : String //Can't seem to get this to be a val
   callTo3rdPartyFunction {
     //Do things
     myReturnVariable = "hello!"
   }
   return myReturnVariable
}
g
ziad: are you returning the results of the function? this has a smell of side effects
you could maybe do
Copy code
return callTo3rd {
 // do stuff
}.let {
 // transform stuff to myReturn
}
z
Hi @gjesse ! Thanks for the input. If it's a smell then I'd love to avoid it. What I'm doing is calling a 3rd party database library that runs a transaction for me. When running the transaction, I'm going to insert a row into a table, and I want to do something with the returned id. For example, return a message that says:
Copy code
"Created item with ID " + X
where X is the result of what happened in that closure.
g
does the 3rd party library return that id?
z
No
g
ah
z
If it did, I guess I could have just done something like:
Copy code
val x = 3rdPartyFunc { //stuff }
g
yeah.. i get it now
i can’t think of a way to do it.. really seems like a limitation of the underlying library. if you use it a lot you can wrap it in a function that does the var + assign & returns the id, so in your everyday code you don’t have to worry about it
z
Hmm, interesting idea. So I'll still use vals in my day to day code, but a var in my wrapper function, right?
g
that’s what i’d do if i had to do it more than 1x
this also might be a good use of extension functions
you can create your own version of the transaction functon and just call it as if it were part of the library (almost)
z
I'll go check out extension functions now, sounds like a good use-case.