-
Notifications
You must be signed in to change notification settings - Fork 1k
Control Structures- Description does not match function's signature #2097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Quick note: |
yes, a PR on this would be welcome |
Altair-Bueno
added a commit
to Altair-Bueno/docs.scala-lang
that referenced
this issue
Aug 11, 2021
Altair-Bueno
added a commit
to Altair-Bueno/docs.scala-lang
that referenced
this issue
Aug 11, 2021
julienrf
added a commit
that referenced
this issue
Aug 30, 2021
Control Structures- Description does not match function's signature #2097
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Control Structures - Using a
match
expression as the body of a method:This method does not only take Boolean as an input, as stated by the function signature. It should work with any
Matchable
value. Also, it does not contain thecase false
neither thecase null
scenario. I'm not sure if it is intended this way or it is an error. I imagine this function tries to mimic JavaScript's behaviour so it should consider those cases too. I added some spaces to ident thetrue
case as it is usually done in other other FP languages like Haskell. I'm not familiar enough with Scala, let me know if my changes are OK and i'll create a pull requestProposed solution
Because
match
expressions return a value, they can be used as the body of a method.This method takes a
Matchable
value as an input parameter, and returns aBoolean
, based on the result of thematch
expression:The input parameter
a
is defined to be the [Matchable
type][matchable]---which is the root of all Scala types that pattern matching can be performed on.The method is implemented by matching on the input, providing two cases:
The first one checks whether the given value is either the integer
0
, an empty string,null
orfalse
and returnsfalse
in this case.In the default case, we return
true
for any other value.These examples show how this method works:
Using a
match
expression as the body of a method is a very common use.The text was updated successfully, but these errors were encountered: