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

  • Home
  • SEARCH
  • 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 6050563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:42:09+00:00 2026-05-23T07:42:09+00:00

I want to do this: abstract class Context { def getInt(id: Int): Int }

  • 0

I want to do this:

abstract class Context {
    def getInt(id: Int): Int
}

abstract class Dependency[+T]
(val name: String, val id: Int)
extends Function1[Context,T]

class IntDependency(name: String, id: Int)
extends Dependency[Int](name, id) {
    def apply(implicit context: Context): Int =
        context.getInt(id)
}

But then I get an error message like this:

class IntDependency needs to be abstract, since method apply in trait
Function1 of type (v1: Context)Long is not defined (Note that T1 does
not match Context)

I understand that implicits should normally be part of the second parameter list, but I can’t work out how to code it so it compiles, and gives the result I want.

Explanation: I’m trying to create a framework where one can define “Function” object, which can depend on other functions to compute their value. All functions should only take a single Context parameter. The context know the “result” of the other functions. The function instances should be immutable, with the state residing in the context. I want the functions to create “dependency” fields at creation time, which take the context implicitly, and return the value of the dependency within that context, so that accessing the dependency inside of the apply method “feels like” accessing a parameter or field, that is without explicitly giving the context as parameter to the dependency.

  • 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-23T07:42:09+00:00Added an answer on May 23, 2026 at 7:42 am

    Are you sure you need your Dependency to extend a Function? Because if you don’t, just leave the extends Function1[Context,T] part out and your code will work.

    If you really need to extend a Function than I don’t know of a solution in your case. But there are cases where you could try to overload the apply method. Like here:

    scala> val sum = new Function1[Int, Function1[Int, Int]] {
             |      def apply(a: Int) = (b: Int) => a + b
             |      def apply(a: Int)(implicit b: Int) = a + b
             |}
    sum: java.lang.Object with (Int) => (Int) => Int{def apply(a:Int)(implicit b: Int): Int} = <function1>
    
    scala> sum(2)(3)
    res0: Int = 5
    
    scala> implicit val b = 10
    b: Int = 10
    
    scala> sum(2)
    res1: Int = 12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code structure: public abstract class ContentEntryBase { public string UniqueIdentifier; public
I have this object graph, I want to map: abstract Account (username, password, ...)
I have this div: <div class=inauguration-image> I do not want this text to display,
I have a class SomeTaskManager with an abstract method runATask . I want to
Is this an acceptable design ?? Abstract class public abstract class SomethingBase { public
I have next structure: @Component public abstract class HuginJob extends QuartzJobBean {...} @Component(CisxJob) public
I want this url http://www.youtube.com/watch?v=dgNgODPIO0w&feature=rec-HM-fresh+div to be transformed to: http://www.youtube.com/v/dgNgODPIO0w with php.
I want this: http://jqueryui.com/demos/dialog/#modal-message to happend when you click on ClickMe. how to do
I want this for some conditional compilation code that will run in all IE's
I want this to be on top... how can I do this and not

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.