score:2
Accepted answer
Scala has separate namespaces for types and values. Your type alias defines what Set
is in the type namespace, but in the definition of singletonSet
Set
comes from the value namespace, in fact it is the companion object scala.collection.immutable.Set
. Set(element)
invokes the apply
method of the companion object, which returns a scala.collection.immutable.Set[Int]
, which turns out to be a subtype of Int => Boolean
and therefore is a Set
(your type alias) as well.
Source: stackoverflow.com
Related Query
- Why calling a function like this works in Scala?
- Why does this Scala function compile when the argument does not conform to the type constraint?
- Why do I need brackets on this nullary function in this Scala expression?
- Why in Scala function defined without empty parentheses doesn't behave like function?
- Can someone explain why applying map like this in Scala throws and IllegalArgumentException?
- Why this function call in Scala is not optimized away?
- Creating a Spark exists user defined function that works like the Scala Array#exists function
- Why is a single element list created like this in Scala Option?
- Why does this scala tail recursive function throws java.lang.StackOverflowError
- Why is the anonymous function and function in Scala constructed like this?
- Calling non-strict function in Scala with explicit types doesn't compile, inferred types works
- Why does Scala fail to compile this function as tail recursive?
- Why is this scala concatenation function not tail recursive?
- Why does this scala function run so much faster using a map compared to a list?
- What's the Scala way to implement a retry-able call like this one?
- Why does a small change to this Scala code make such a huge difference to performance?
- Why are there two sets of arguments/parenthesis in this Scala method definition?
- Why is this Scala code with assignment of a val in a parameter working?
- Why to use empty parentheses in Scala if we can just use no parentheses to define a function which does not need any arguments?
- Why does Scala not have a return/unit function defined for each monad (in contrast to Haskell)?
- Why scala people don't like annotation?
- Why does this explicit call of a Scala method allow it to be implicitly resolved?
- Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?
- Why this scala code reports compilation error: recursive value x needs type
- Scala perf: Why is this Scala app 30x slower than the equivalent Java app?
- Confused about Scala method calling conventions, specifically the sum function on Seq
- Scala Function.tupled and Function.untupled equivalent for variable arity, or, calling variable arity function with tuple
- Why does Scala allow nested data structures like List or Array
- Why and how is Scala treating a tuple specially when calling a one arg function?
- Function Overhead in Functional Languages like Haskell or in Hybrids like Scala
More Query from same tag
- how to convert map into repeated tuple in scala
- Chaining scala Try instances that contain Options
- scala generic function reference
- Scala Currying: Overriding function with an empty argument by a partial function
- Scala Play 2.1.0 - Assets not appearing on Heroku?
- Scala Play WS.put Array[Bytes] setting negative bytes to 0b111111
- Can't get the Scala tools to work in Odersky's Coursera course
- How to obtain the source and javadoc files?
- Structural types in Dotty/Scala 3 compiled failed?
- Transformation of List[(Object1,Object2)] to Map[Object1, List[Object2]] - Scala
- How to add a new nullable String column in a DataFrame using Scala
- Spark select column based on row values
- How to break early when foldLeft over simple List?
- Scala: List of class objects printing the class variable/attributes
- How should I specify the type of JSON-like unstructured data in Scala?
- How would I get a list of constructor arguments for a case class in Scala?
- In Scala project: How to add dependency Jar details into Manifest file
- sbteclipse 2.4.0 doesn't work with sbt 0.13.1 and Scala 2.10.3, on Fedora 20 XFCE
- Dynamic configuration management
- Enforcing precedence in implicit instances in Scala
- play-cache -- memorize an Future with expiration which depends on the value of future
- Creating json having different keys and values with spray
- Failing to include com.typesafe in build.sbt (for Scala and spray on Heroku)
- How can online code editor Scastie read an input file?
- getting a java.io.Serializable from Option[..] in Scala
- Serializing sequences of AnyVal with json4s
- Scala. Case class copy from trait reference
- Matrix as Applicative functor, which is not Monad
- Scala Either : simplest way to get a property that exists on right and left
- Gradle Scala plugin - How to specify scala version