id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
kotlin_ObservableProperty_delegates/7_28_0.txt | ### A minute assignment
Implement the ` toMinsAndSecs ` function we contemplated earlier. It should
work like this: | |
kotlin_ObservableProperty_delegates/showthread.php3_42_0.txt | > Originally Posted by wolle Unfortunately I've no experience with C++98.
>
> The only quick solution I can think of without too many changes is to only
> assign data when the map is empty. This will be the case once only. The
> check of whether the map is empty happens each time the function is called
> but it ... | |
kotlin_ObservableProperty_delegates/8836_5_0.txt | Find and fix vulnerabilities
* Codespaces | |
kotlin_ObservableProperty_delegates/8_8_0.txt | « Chapter 8.3: Robots and Conditional Looping Course materials Week 9 »
1. CS-A1110
2. Week 8
3. Chapter 8.4: Pairs and Maps | |
kotlin_ObservableProperty_delegates/8_103_0.txt | Question 1
Can you use this same method to check if the English word ` "tapir" ` is in
our dictionary? That is, does ` contains ` search the values as well as the
keys? Try it. | |
kotlin_ObservableProperty_delegates/8836_35_0.txt | easazade opened this issue Aug 4, 2020 · 34 comments
Closed | |
kotlin_ObservableProperty_delegates/8_88_0.txt | The difference to the familiar collection types is that a map’s elements are
always key–value pairs.
A map has two type parameters: the type of the keys and the type of the
values. In this example, we have a map whose keys and values are both strings. | |
kotlin_ObservableProperty_delegates/8836_148_0.txt | 25 participants
and others | |
kotlin_ObservableProperty_delegates/8_5_0.txt | * Home
* Begin by enrolling in a course.
* Log in
* Skip course navigation
* #### Language | |
kotlin_ObservableProperty_delegates/8836_121_0.txt | Sorry, something went wrong.
Copy link | |
kotlin_ObservableProperty_delegates/8_98_0.txt | This command also replaces any previously stored key–value pair that has the
same key.
The rest of this ebook uses this second notation to add pairs to a map. You
can use whichever you prefer. | |
kotlin_ObservableProperty_delegates/7_121_0.txt | Question 1
Can you use this same method to check if the English word ` "tapir" ` is in
our dictionary? That is, does ` contains ` search the values like it searches
the keys? Try it. | |
kotlin_ObservableProperty_delegates/7_30_0.txt | A+ presents the exercise submission form here.
Here’s a variation on a question from Chapter 1.4 | |
kotlin_ObservableProperty_delegates/8_112_0.txt | We give the ` map ` method a function that leaves the first member of each
key–value pair untouched.
Flipping a ` Map ` | |
kotlin_ObservableProperty_delegates/8836_37_0.txt | ## Comments
Copy link | |
kotlin_ObservableProperty_delegates/7_130_0.txt | We use a two-parameter function literal whose parameters have descriptive
names. There’s no need to mess about with indices.
In many programs, it is useful to construct a new ` Map ` whose keys are
identical to an existing ` Map ` ’s keys but whose values are different from
the original map’s. As a little example, l... | |
kotlin_ObservableProperty_delegates/7_61_0.txt | A detailed hint on which methods to use
Show Hide | |
kotlin_ObservableProperty_delegates/7_109_0.txt | It’s simple to fetch a value that matches a key:
finnishToEnglish.get("kissa")res28: Option[String] = Some(cat)
finnishToEnglish.get("Mikki-Hiiri")res29: Option[String] = None
| |
kotlin_ObservableProperty_delegates/7_118_0.txt |
finnishToEnglish -= "laama"res33: Map[String, String] = Map(koira -> dog, tapiiri -> tapir, kissa -> cat, sika -> pig, hiiri -> mouse)
There’s also a ` remove ` method that returns the removed value in an `
Option ` wrapper: | |
kotlin_ObservableProperty_delegates/7_29_0.txt |
toMinsAndSecs(187)res4: (Int, Int) = (3,7)
val (min, s) = toMinsAndSecs(200)min: Int = 3
s: Int = 20
Write your solution in ` o1/misc.scala ` in module Miscellaneous. | |
kotlin_ObservableProperty_delegates/8_171_0.txt | ×
#### | |
kotlin_ObservableProperty_delegates/8836_31_0.txt | 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. | |
kotlin_ObservableProperty_delegates/8836_51_0.txt | Copy link
### | |
kotlin_ObservableProperty_delegates/8836_25_0.txt | Query
To see all available qualifiers, see our documentation . | |
kotlin_ObservableProperty_delegates/8836_126_0.txt | Copy link
### | |
kotlin_ObservableProperty_delegates/7_56_0.txt |
def heightDescription(cm: Int, species: String) =
s"a typical $species is $cm cm at the shoulder"def heightDescription(cm: Int, species: String): String
heightsAndSpecies.map(heightDescription).foreach(println)a typical llama is 120 cm at the shoulder
a typical alpaca is 90 cm at the shoulde... | |
kotlin_ObservableProperty_delegates/7_46_0.txt | If the collections have different lengths, the longer collection’s tail end is
ignored:
val moreSpecies = Vector("llama", "alpaca", "vicuña", "guanaco", "wooly")moreSpecies: Vector[String] = Vector(llama, alpaca, vicuña, guanaco, wooly)
val justThreePairs = heights.zip(moreSpecies)justThreePairs: Vec... | |
kotlin_ObservableProperty_delegates/7_131_0.txt |
val lengthOfEnglish = finToEng.map( (fin, eng) => fin -> eng.length )lengthOfEnglish: Map[String,String] = Map(kissa -> 3, tapiiri -> 5, koira -> 3)
We give the ` map ` method a function that leaves the first member of each
key–value pair untouched. | |
kotlin_ObservableProperty_delegates/8_75_0.txt |
("koira", "dog")res17: (String, String) = (koira,dog)
However, when defining key–value pairs, it’s common to use another notation
that highlights the fact that each key “points at” the corresponding value.
The following code produces precisely the same output as the code above: | |
kotlin_ObservableProperty_delegates/7_124_0.txt |
finnishToEnglish.keys.foreach(println)koira
tapiiri
kissa
sika
hiiri
finnishToEnglish.values.foreach(println)dog
tapir
cat
pig
mouse
### Familiar methods on ` Map ` s | |
kotlin_ObservableProperty_delegates/8_135_0.txt |
class Member(val id: Int, val name: String, val yearOfBirth: Int, val yearOfDeath: Option[Int]) {
// etc.
}
Now, let’s write another class, ` Society ` , that stores the members of a
society in an instance variable that refers to a ` Map ` . | |
kotlin_ObservableProperty_delegates/8836_85_0.txt | Sorry, something went wrong.
Copy link | |
kotlin_ObservableProperty_delegates/7_99_0.txt | The target object whose method we call.
This method, whose name consists of a hyphen and a greater-than sign, is
available on all Scala objects. Here, we have used operator notation (Chapter
5.2 ), which omits the period-dot between the target object and the method
name. | |
kotlin_ObservableProperty_delegates/8836_91_0.txt | Sorry, something went wrong.
Copy link | |
kotlin_ObservableProperty_delegates/8836_147_0.txt | Development
No branches or pull requests | |
kotlin_ObservableProperty_delegates/8836_79_0.txt | StitchC commented Jan 8, 2022
+1
my issue is info: type '_TwoByteString' is not a subtype of type 'bool'
what a serious!
---
All reactions | |
kotlin_ObservableProperty_delegates/showthread.php3_34_0.txt | 7. August 7th, 2019, 12:00 PM #7 2kaud
* View Profile
* View Forum Posts
Super Moderator Power Poster
Join Date | |
kotlin_ObservableProperty_delegates/7_16_0.txt | Can a function return two values? Could we, for instance, define a function `
toMinsAndSec ` that takes in a number of seconds and returns two integers:
the number of whole minutes and the leftover seconds? Perhaps it would work
like this:
toMinsAndSecs(187)res0: (Int, Int) = (3,7)
| |
kotlin_ObservableProperty_delegates/7_157_0.txt | The ` Society ` object has methods for adding members and finding existing
members by their ID. These methods have been implemented by calling the ` Map
` ’s methods.
### Mini-assignment: ` Map ` s and ` Option ` | |
kotlin_ObservableProperty_delegates/7_134_0.txt | Here’s the ` swap ` operation applied to an entire ` Map ` :
val finnishToEnglish = Map("kissa" -> "cat", "koira" -> "dog", "laama" -> "llama")finnishToEnglish: Map[String,String] = Map(kissa -> cat, koira -> dog, laama -> llama)
val englishToFinnish = finnishToEnglish.map( _.swap )englishToFinnish... | |
kotlin_ObservableProperty_delegates/8_130_0.txt | The keys of this ` Map ` are letters (characters).
The values of this ` Map ` are letters (characters). | |
kotlin_ObservableProperty_delegates/8836_117_0.txt | IguJl15 commented Nov 24, 2022
I am getting the same error when trying to parse a value from api to bool. But
I realized that the api I am using is sending boolean in text ( ` "true" `
instead of the true boolean ` true ` ). In our case, this occurs as a safety
measure against null values. We created a CustomBoole... | |
kotlin_ObservableProperty_delegates/7_146_0.txt | ` get ` — good or bad?
So, the ` get ` method of ` Map ` objects is good? Even though the ` get `
method of ` Option ` objects is bad (as discussed in the optional sections of
4.4 and 8.4 )? | |
kotlin_ObservableProperty_delegates/7_70_0.txt |
val nameAndNumber = ("Juha", 43)nameAndNumber: (String, Int) = (Juha,43)
nameAndNumber._1res16: String = Juha
nameAndNumber._2res17: Int = 43
The first member of a tuple has the name ` _1 ` . That’s one, not zero! The
second member is ` _2 ` (and so forth). | |
kotlin_ObservableProperty_delegates/7_23_0.txt |
("good thing", "another thing")res1: (String, String) = (good thing,another thing)
There are brackets in the REPL output, too. ` (String, String) ` means a
pair whose members are both strings. | |
kotlin_ObservableProperty_delegates/7_148_0.txt | Question 1
Suppose we’ve created a ` Map ` and a variable that refers to it: | |
kotlin_ObservableProperty_delegates/8_153_0.txt | Please note that this section must be completed individually. Even if you
worked on this chapter with a pair, each of you should submit the form
separately.
Time spent: (*) Required | |
kotlin_ObservableProperty_delegates/8_60_0.txt | * In a tuple, each member has a distinct static type. In a collection, the elements share a static type.
* Tuples are always immutable in size and content. Collections come in both mutable and immutable varieties.
* Tuples don’t have the familiar collection methods ( ` size ` , ` map ` , ` indexOf ` , etc.) ... | |
kotlin_ObservableProperty_delegates/8836_14_0.txt | Resources
* Learning Pathways
* White papers, Ebooks, Webinars
* Customer Stories
* Partners | |
kotlin_ObservableProperty_delegates/8_165_0.txt | Additional credits appear at the ends of some chapters.
Posting submission... | |
kotlin_ObservableProperty_delegates/8836_2_0.txt | * Product
* Actions | |
kotlin_ObservableProperty_delegates/8_46_0.txt | We get a vector of pairs, each of which contains a string and an integer.
When you loop over such a collection of pairs, you can again use round
brackets to deal with two variables at once. Here are two ways of printing out
a collection of pairs: | |
kotlin_ObservableProperty_delegates/7_98_0.txt | ` -> ` is an ordinary method.
"seikkailija" -> "adventurer"res25: (String, String) = (seikkailija,adventurer)
| |
kotlin_ObservableProperty_delegates/7_74_0.txt | * A student register: we want to be able to search for students by their student ID number.
* An address book: we want to be able to find the person object that details an individual whose name we know. | |
kotlin_ObservableProperty_delegates/8836_39_0.txt | edited
This is an error I get only in release mode (weird) when I'm trying to parse
response body of a network request i made into a json map. I put down the code
and also the error stacktrace below.
the other wierd thing i should mention is that it only happens sometimes. not
all the time. but for the apps i have r... | |
kotlin_ObservableProperty_delegates/7_13_0.txt | What Will I Do? Read and work on small assignments.
Rough Estimate of Workload: ? Two hours. | |
kotlin_ObservableProperty_delegates/8_146_0.txt | Which of the claims below are correct?
The command ` finnishScrabble2('A') ` returns an ` Int ` . | |
kotlin_ObservableProperty_delegates/showthread.php3_19_0.txt | Reply With Quote
* * * | |
kotlin_ObservableProperty_delegates/7_120_0.txt | The ` contains ` method tells us if a given key is present in the map. In the
example below, ` "tapiiri" ` is present in the dictionary whereas ` "laama"
` , which we just removed, is not.
finnishToEnglish.contains("tapiiri")res35: Boolean = true
finnishToEnglish.contains("laama")res36: Boolean = f... | |
kotlin_ObservableProperty_delegates/7_43_0.txt |
val species = Vector("llama", "alpaca", "vicuña")species: Vector[String] = Vector(llama, alpaca, vicuña)
species.zipWithIndexres6: Vector[(String, Int)] = Vector((llama,0), (alpaca,1), (vicuña,2))
We get a vector of pairs, each of which contains a string and an integer. | |
kotlin_ObservableProperty_delegates/7_25_0.txt | A key difference between a pair and, say, a two-element vector is that a
pair’s members can have different static types:
val nameAndShoeSize = ("Juha", 43)nameAndShoeSize: (String, Int) = (Juha,43)
| |
kotlin_ObservableProperty_delegates/8836_151_0.txt | You can’t perform that action at this time.
| |
kotlin_ObservableProperty_delegates/8836_131_0.txt | Sorry, something went wrong.
Copy link | |
kotlin_ObservableProperty_delegates/8_160_0.txt | The appendices ( glossary , Scala reference , FAQ , etc.) are by Juha
Sorva unless otherwise specified on the page.
The automatic assessment of the assignments has been developed by: (in
alphabetical order) Riku Autio, Nikolas Drosdek, Joonatan Honkamaa, Jaakko
Kantojärvi, Niklas Kröger, Teemu Lehtinen, Strasdos... | |
kotlin_ObservableProperty_delegates/7_77_0.txt |
val searchTerms = Buffer("kissa", "laama", "tapiiri", "koira")searchTerms: Buffer[String] = ArrayBuffer(kissa, laama, tapiiri, koira)
val englishTranslation = Buffer("cat", "llama", "tapir", "puppy")englishTranslation: Buffer[String] = ArrayBuffer(cat, llama, tapir, puppy)
We can use these two b... | |
kotlin_ObservableProperty_delegates/8_23_0.txt |
("good thing", "another thing")res1: (String, String) = (good thing,another thing)
There are brackets in the REPL output, too. ` (String, String) ` means a
pair whose members are both strings. | |
kotlin_ObservableProperty_delegates/8_118_0.txt | You already know that a ` Map ` ’s ` get ` method returns an ` Option ` ,
which is ` None ` in case the key wasn’t found:
finToEng.get("Mikki-Hiiri")res35: String = None
| |
kotlin_ObservableProperty_delegates/7_158_0.txt | You’ll find ` Society ` in module Miscellaneous. Add a ` yearOfDeath `
method to the class. The method should:
* receive a member ID as a parameter; | |
kotlin_ObservableProperty_delegates/8_149_0.txt | What’s the hash?
The “hash” in ` HashMap ` has nothing to do with Twitter or any other
pastimes. It refers to a particular way of implementing ` Map ` s. | |
kotlin_ObservableProperty_delegates/8836_16_0.txt | Fund open source developers
* The ReadME Project | |
kotlin_ObservableProperty_delegates/7_15_0.txt | ## Introduction: Two Return Values?
### Frequently asked question | |
kotlin_ObservableProperty_delegates/7_116_0.txt | This command also replaces any previously stored key–value pair that has the
same key.
The rest of this ebook uses this second notation to add pairs to a map. You
can use whichever you prefer. | |
kotlin_ObservableProperty_delegates/8_90_0.txt | As you read these examples, you’ll notice that there are (again) a number of
ways to do the same thing. It’s unlikely that you’ll be able to tell right
away which solution is the best fit for which situation. Then again, you don’t
need to; that’s the sort of thing that improves with experience. It’s good to
learn to re... | |
kotlin_ObservableProperty_delegates/7_184_0.txt | The illustrations at the top of each chapter, and the similar drawings
elsewhere in the ebook, are the work of Christina Lassheikki.
The animations that detail the execution Scala programs have been designed by
Juha Sorva and Teemu Sirkiä. Teemu Sirkiä and Riku Autio did the technical
implementation, relying on Teemu’... | |
kotlin_ObservableProperty_delegates/8_7_0.txt | * CS-A1110
* Course materials
* Your points
* Form a group
* Code Vault
* Lab Queue
* Telegram chat
* Lab sessions
* Glossary
* Scala reference
* O1Library docs
* FAQ
* IntelliJ installation
* Learning goals
* Style guide
* Debugger
* Resources
* For the reader
Thi... | |
kotlin_ObservableProperty_delegates/8836_116_0.txt | Copy link
### | |
kotlin_ObservableProperty_delegates/8_108_0.txt | The ` map ` method (lower case) is worth a special mention. You can use it to
process the key–value pairs of a ` Map ` (upper case) in order to create a
new ` Map ` :
val myTestMap = finToEng.map( pair => pair._1.toUpperCase -> (pair._2 + "!!!") )myTestMap: Map[String,String] = Map(KISSA -> cat!!!, TA... | |
kotlin_ObservableProperty_delegates/8836_137_0.txt | Copy link
### | |
kotlin_ObservableProperty_delegates/showthread.php3_38_0.txt | Reply With Quote
* * * | |
kotlin_ObservableProperty_delegates/8836_94_0.txt | Copy link
### | |
kotlin_ObservableProperty_delegates/8_58_0.txt | First of all, tuples and collections have different purposes. Tuples tend to
be most useful when: 1) there is a small, constant number of members (e.g.,
only two), and 2) each member has a meaning separate from the others (e.g.,
one signifies minutes, the other seconds; one is a name, the other is a shoe
size), but 3) ... | |
kotlin_ObservableProperty_delegates/7_11_0.txt | # Chapter 9.2: Pairs and Maps
About This Page | |
kotlin_ObservableProperty_delegates/8_121_0.txt | We give ` getOrElse ` the search key and a “default value” that should match
the type of the ` Map ` ’s values.
If the key is present in the ` Map ` , ` getOrElse ` returns the
corresponding value. | |
kotlin_ObservableProperty_delegates/8836_71_0.txt | ###
Maged12 commented Jul 16, 2021 | |
kotlin_ObservableProperty_delegates/8836_103_0.txt | PawanFyers commented Sep 29, 2022
We have seen the same issue on Crashlytics console:
` io.flutter.plugins.firebase.crashlytics.FlutterError: Exception type
'_OneByteString' is not a subtype of type 'int' `
---
All reactions | |
kotlin_ObservableProperty_delegates/7_48_0.txt | ### A pair as a parameter
Naturally, you can also define a function that takes a pair as a parameter.
The example function below takes a pair of numbers and returns the absolute
value of their difference. | |
kotlin_ObservableProperty_delegates/showthread.php3_14_0.txt | > Last edited by wolle; August 7th, 2019 at 08:51 AM .
Reply With Quote | |
kotlin_ObservableProperty_delegates/7_132_0.txt | Flipping a ` Map `
A frequently asked question: how can you make a ` Map ` whose keys are the
values of an existing ` Map ` and whose values are the original ` Map ` ’s
keys? | |
kotlin_ObservableProperty_delegates/8836_127_0.txt | WiRight commented Dec 26, 2022
Check your StackTrace. The first 10 lines will be enough. Cover your ` runApp
` with ` runZonedGuarded ` or ` try/catch ` with getting
StackTrace/StackTrace.current and in 90% it will be some Map with wrong key
data
---
All reactions | |
kotlin_ObservableProperty_delegates/7_68_0.txt | Tuples and case classes
The optional material in Chapter 4.4 briefly introduced Scala’s ` case
class ` construct. In a sense, a case class is a sort of customized tuple.
For more on case classes, see the spring course Programming Studio 2 . | |
kotlin_ObservableProperty_delegates/8836_86_0.txt | ###
a475893401 commented Mar 15, 2022 | |
kotlin_ObservableProperty_delegates/8_72_0.txt | It’s true that we’ve been already using a method named ` map ` . The two
concepts are distinct but there is a reason why their names are similar.
The familiar ` map ` -that-is-a-method takes an existing collection and uses
its elements to generate another. The parameter function of ` map ` defines a
mapping from ... | |
kotlin_ObservableProperty_delegates/8_66_0.txt | The same basic pattern repeats in all the other scenarios listed above:
student ID numbers as keys, the student objects as values; director names as
keys, the movie counts of the directors as values; etc. In the following text,
we will use the terms “key” and “value” in this sense.
Our buffer-based solution relies on ... | |
kotlin_ObservableProperty_delegates/7_147_0.txt | Yes, that’s right.
### Practice on ` get ` , ` apply ` , and ` getOrElse ` | |
kotlin_ObservableProperty_delegates/7_144_0.txt | ` Map ` s, too, have an ` apply ` method. It works much like ` get ` , but
there is a substantial difference. Compare:
val engToFin = Map("kissa" -> "cat", "tapiiri" -> "tapir", "koira" -> "dog")engToFin: Map[String,String] = Map(koira -> dog, tapiiri -> tapir, kissa -> cat)
engToFin("tapiiri")res... | |
kotlin_ObservableProperty_delegates/7_142_0.txt | If the key isn’t present, the method returns the value of its second
parameter.
The return type is ` String ` rather than ` Option[String] ` . We don’t need
an ` Option ` wrapper since we have a meaningful ` String ` value in both
cases. Lovely. | |
kotlin_ObservableProperty_delegates/8836_135_0.txt | ###
AlexV525 commented Mar 23, 2023 | |
kotlin_ObservableProperty_delegates/8_83_0.txt | We could have used the dot notation. These two expressions are equivalent:
"polvi".->("knee")res21: (String, String) = (polvi,knee)
"polvi" -> "knee"res22: (String, String) = (polvi,knee)
| |
kotlin_ObservableProperty_delegates/8_105_0.txt | ### Getting all the keys or all the values
The methods ` keys ` and ` values ` return all the keys and all the values
of a map, respectively. These methods return collections that you can process
with the usual methods. Here, for instance, we first print out all the keys
followed by all the values. | |
kotlin_ObservableProperty_delegates/ObservableProperty_3_0.txt | [ ](https://kotlinlang.org) [ v1.9.23
](https://github.com/JetBrains/kotlin/releases/tag/v1.9.23)
* Solutions
* [ Multiplatform ](/lp/mobile/)
* [ Server-side ](/lp/server-side/)
* [ Data science ](/docs/data-science-overview.html)
* [ Android ](/docs/android-overview.html)
* [ Docs ](/docs/home.h... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.