Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:38:18+00:00 2026-05-29T22:38:18+00:00

If I have the following code: val wows = Buffer[Wow]() def yo(f: _ =>

  • 0

If I have the following code:

val wows = Buffer[Wow]()

def yo(f: _ => Wow) { wows += f }

and I get an error when trying to add f. I wonder, how can I use f inside the method body, or more precisely, how should I refer to it since f or f() or f(_) do not work.

UPDATE:

The type of f cannot be changed to f: => Wow because the functions of type _ => Wow passed to this method come from such a class:

object Wonderful {

    val wows = Buffer[Wow]()

    def yo(f: _ => Wow) { wows += f }
}

class Joy[+R](fs: Buffer[_ => R]) {

    def exalt() {
        fs.map(Wonderful.yo(_))
    }
}

and that buffer cannot be parametrized with => R, it shows an error.

UPDATE 2: Both of you have second-answered before I have finished the explanation of the second part! Thanks! That’s the speed!

UPDATE 3: Basically, I am learning Scala and I am trying to try out all that I can think of. In this particular piece of code, there happens the following thing: I have 3 basic classes:

  • WorldObject – represents all game objects (has x, y and such).
  • Emitter – represents something that emits objects over time (extends WorldObject).
  • Funset – a set of functions that should produce WorldObjects when called. In future I wanted to make them partially applied functions with some prepared arguments, passed directly to the corresponding factory methods.
  • World – where everything takes place.

The main point is that a Funset’s collection of “generative” functions can be edited during runtime, that is why it is represented as buffer. On every update cycle an Emitter passes each of Funsets functions to the World’s creator functions that manifest the generated objects in the world.

I hope I have explained so it can be understood… maybe a little bizzare or a wrong architecture, but.. anyways, I have learned something about Scala now!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:38:19+00:00Added an answer on May 29, 2026 at 10:38 pm

    _ => Wow is a method that takes a single argument of a type that you don’t know and returns a Wow. You won’t be able to call it since you don’t know what sort of argument to call it with!

    I suspect you want a method with no arguments, which you could do like the following:

    def yo( f: () => Wow ) { wows += f() }
    

    Also you can do a by-name parameter which is a little bit more implicit:

    def you( f: => Wow ) { wows += f }
    

    Edit: The difference is in how you call it; a by-name parameter just evaluates an expression when it is used. Passing a function is actually just passing a function which you can call at will.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $(#tag-add-button).click(function () { var text = $(#tagadd).val(); var tagcounter=0;
I have the following (working) code val superSuperSorts = superSorts.flatMap(relations.get(_)).flatMap(x=>x) And I give you
I have following code snippet that i use to compile class at the run
I have the following code: function reload() { var referenceID = $('#ReferenceID').val(); $('#detailData').load(Url.Action(DetailData, new
I have the following code: jQuery('#hexVal').change(function() { var hexvarval = jQuery('#hexVal').val(); jQuery('#thumbnail_hover_color').val(hexvarval); }); Basically,
I have the following code $('#check-twitter').click( function() { if ($('#ShareTwitterPublish').val() == '0') { $('#ShareTwitterPublish').val('1');
I have the following code datePicker.change(function(){ dateSet = datePicker.val(); dateMinimum = dateChange(); dateSetD =
I have this following code: $(.preview).find(#panel).each(function(i, val) { var x = + $(val).html(); $(x).find(.dmPageHeadline).prepend(
I have the following code. template<class key,class val> bool has_key(key chkey,std::map<key,val> map){ for (std::map<key,val>::iterator
I have used following code to add three variables but instead of adding these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.