Scala is an expression oriented language, so the last thing you refer to is
returned.

def foo: Int = 3

returns 3. There is no need to use the return keyword, indeed its use can
complicate matters as you can create non-local returns, which I suspect is
what is confusing you in your example.

There are some very good books that explain how Scala works, as well as
some good online tutorials. The book "Functional Programming in Scala" is
an excellent book introducing the various concepts of FP and how to use
them effectively. It does help to have a basic general knowledge of the
language though, so may not be the ideal introduction.

For further questions about how the basics of the language work, there are
many links on the https://www.scala-lang.org/community/ page.

On Wed, 8 May 2019 at 12:19, tushar pandit <tushar.pandi...@gmail.com>
wrote:

> now I need to return* this object
>
> On Tuesday, May 7, 2019 at 9:18:26 PM UTC-5, tushar pandit wrote:
>>
>> Yeah. I am sorry to put it in a confusing manner. Yeah I am working with
>> Druid in Scala, but my question is about Scala code itself. So consider I
>> get some data from some data store (in my case it is Druid), I get the
>> dataset in an object and now I need to pass this object to the calling
>> function. I am unable to do this.
>>
>> To simplify the code:
>>
>> def main(args: Array[String]): Unit = {
>>   val res = fetchData()
>>
>>   // res comes as null here
>> }
>>
>> def fetchData():Any {
>>
>>   client(query).onComplete {
>>     case Success(resp) =>
>>
>>       *return resp*
>>     case Failure(ex) =>
>>       ex.printStackTrace()
>>
>>       return null
>>   }
>> }
>>
>>
>> So my "res" in "main" method does not hold any results after the call is
>> done. But when I try to print the "resp" in "success" it prints all the
>> fetched data.
>>
>> On Tuesday, May 7, 2019 at 9:13:41 PM UTC-5, jed.wesleysmith wrote:
>>>
>>> Tushar, this seems to be an issue with whatever Druid is. This mailing
>>> list is for questions about Functional Programming in Scala, both in
>>> general and more specifically the book with that title. If you ask your
>>> question in a more relevant forum somebody may be able to provide you with
>>> an answer.
>>>
>>> On Wed, 8 May 2019 at 12:06, tushar pandit <tushar....@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I am trying to call function fetchFromDruid
>>>>
>>>> def main(args: Array[String]): Unit = {
>>>>   val res = fetchFromDruid()
>>>>
>>>>   // res comes as null here
>>>> }
>>>>
>>>> def fetchFromDruid(): GroupByResponse {
>>>>   implicit val executionContext = ExecutionContext.Implicits.global
>>>>   val client = DruidClient("http://localhost:8082";)
>>>>
>>>>   val query = GroupByQuery(
>>>>     source = "wikipedia",
>>>>     interval = new Interval(new DateTime().minusMonths(60), new 
>>>> DateTime()),
>>>>     dimensions = Seq("countryName"),
>>>>     descending = true,
>>>>     granularity = Granularity.All,
>>>>     aggregate = Seq(
>>>>       DSL.count("row_count")
>>>>     ),
>>>>     postAggregate = Seq(
>>>>     ),
>>>>     limit = Some(100)
>>>>   )
>>>>
>>>>   client(query).onComplete {
>>>>     case Success(resp) =>
>>>>       resp.data.foreach { row =>
>>>>         println(row)
>>>>       }
>>>>
>>>>       *return resp*
>>>>       println("none")
>>>>     //System.exit(0)
>>>>     case Failure(ex) =>
>>>>       ex.printStackTrace()
>>>>
>>>>       return null
>>>>     //System.exit(0)
>>>>   }
>>>> }
>>>>
>>>>
>>>> But somehow I am not able to return the response to the caller; i.e the 
>>>> main function. What could be the issue?
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Tushar
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "scala-functional" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to scala-fu...@googlegroups.com.
>>>> To view this discussion on the web, visit
>>>> https://groups.google.com/d/msgid/scala-functional/8bc53b5e-729d-497d-89bd-ab2568674cc7%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/scala-functional/8bc53b5e-729d-497d-89bd-ab2568674cc7%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "scala-functional" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scala-functional+unsubscr...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/scala-functional/c8a0dac0-5163-4de9-a389-e63767b4b4f6%40googlegroups.com
> <https://groups.google.com/d/msgid/scala-functional/c8a0dac0-5163-4de9-a389-e63767b4b4f6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"scala-functional" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to scala-functional+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/scala-functional/CAN3nywCUdLBwfPUfVXHnsT0ds2_MgaK3JE6%3DNnZTkOLFYoJdNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to