{"id":651,"date":"2011-10-03T21:58:00","date_gmt":"2011-10-03T21:58:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/scala-tutorial-iteration-for-expressions-yield-map-filter-count.html"},"modified":"2012-10-21T20:33:04","modified_gmt":"2012-10-21T20:33:04","slug":"scala-tutorial-iteration-for","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html","title":{"rendered":"Scala Tutorial &#8211; iteration, for expressions, yield, map, filter, count"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">\n<h2>         Preface<\/h2>\n<p>This is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other resources on <a href=\"http:\/\/icl-f11.utcompling.com\/links\">the links page of the Computational Linguistics course<\/a> I\u2019m creating these for. Additionally you can find this and other tutorial series on the JCG <a href=\"http:\/\/www.javacodegeeks.com\/p\/java-tutorials.html\">Java Tutorials<\/a> page.<\/p>\n<p>This tutorial departs from the very beginner nature of the previous three, so this may be of more interest to readers who already have some programming experience in another language. (Though also, see the section on <a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/scala-tutorial-conditional-execution.html\">using matching in Scala in Part 3<\/a>.)<\/p>\n<h2>         Iteration, the Scala way(s)<\/h2>\n<p>Up to now, we have (mostly) accessed individual items on a list by using their indices. But one of the most natural things to do with a list is to repeat some action for each item on the list, for example: \u201cFor each word in the given list of words: print it\u201d. Here is how to say this in Scala.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val animals = List(\"newt\", \"armadillo\", \"cat\", \"guppy\")\r\nanimals: List[java.lang.String] = List(newt, armadillo, cat, guppy)\r\n \r\nscala&gt; animals.foreach(println)\r\nnewt\r\narmadillo\r\ncat\r\nguppy\r\n<\/pre>\n<p>This says to take each element of the list (indicated by <strong>foreach<\/strong>) and apply a function (in this case, <strong>println<\/strong>) to it, in order. There is some underspecification going on in that we aren\u2019t providing a variable to name elements. This works in some cases, such as above, but won\u2019t always be possible. Here\u2019s is how it looks in full, with a variable naming the element.<\/p>\n<pre class=\"brush: scala;\">scala&gt; animals.foreach(animal =&gt; println(animal))\r\nnewt\r\narmadillo\r\ncat\r\nguppy\r\n<\/pre>\n<p>This is useful when you need to do a bit more, such as concatenating a String element with another String.<\/p>\n<pre class=\"brush: scala;\">scala&gt; animals.foreach(animal =&gt; println(\"She turned me into a \" + animal))\r\nShe turned me into a newt\r\nShe turned me into a armadillo\r\nShe turned me into a cat\r\nShe turned me into a guppy\r\n<\/pre>\n<p>Or, if you are performing a computation with it, like outputing the length of each element in a list of strings.<\/p>\n<pre class=\"brush: scala;\">scala&gt; animals.foreach(animal =&gt; println(animal.length))\r\n4\r\n9\r\n3\r\n5\r\n<\/pre>\n<p>We can obtain the same result as <strong>foreach<\/strong> using a <strong>for<\/strong> expression.<\/p>\n<pre class=\"brush: scala;\">scala&gt; for (animal &lt;- animals) println(animal.length)\r\n4\r\n9\r\n3\r\n5\r\n<\/pre>\n<p>With what we have been doing so far, these two ways of expressing the pattern of iterating over the elements of a List are equivalent. However, they are different: a <strong>for expression<\/strong> returns a value, whereas <strong>foreach<\/strong> simply performs some function on every element of the list. This latter kind of use is  termed a <em>side-effect<\/em>: by printing out each element, we are not creating new values, we are just performing an action on each element. With <strong>for expressions<\/strong>, we can yield values that create transformed Lists. For example, contrast using <strong>println<\/strong> with the following.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val lengths = for (animal &lt;- animals) yield animal.length\r\nlengths: List[Int] = List(4, 9, 3, 5)\r\n<\/pre>\n<p>The result is a new list that contains the lengths (number of characters) of each of the elements of the <em>animals<\/em> list. (You can of course print its contents now by doing <strong>lengths.foreach(println)<\/strong>, but typically we want to do other, usually more interesting, things with such values.)<\/p>\n<p>What we just did was map the values of <em>animals<\/em> into a new set of values in a one-to-one manner, using the function <strong>length<\/strong>. Lists have another function called <strong>map<\/strong> that does this directly.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val lengthsMapped = animals.map(animal =&gt; animal.length)\r\nlengthsMapped: List[Int] = List(4, 9, 3, 5)\r\n<\/pre>\n<p>So, the <strong>for-yield expression<\/strong> and the <strong>map<\/strong> method achieve the same output, and in many cases they are pretty much equivalent. Using <strong>map<\/strong>, however, is often more convenient because you can easily chain a series of operations together. For example, let\u2019s say you want to add 1 to a List of numbers and then get the square of that, so turning List(1,2,3) into List(2,3,4) into List(4,9,16). You can do that quite easily using map.<\/p>\n<pre class=\"brush: scala;\">nums.map(x=&gt;x+1).map(x=&gt;x*x)\r\n<\/pre>\n<p>Some readers will be puzzled by what was just done. Here it is more explicitly, using an intermediate variable <em>nums2<\/em> to store the add-one list.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val nums2 = nums.map(x=&gt;x+1)\r\nnums2: List[Int] = List(2, 3, 4)\r\n \r\nscala&gt; nums2.map(x=&gt;x*x)\r\nres9: List[Int] = List(4, 9, 16)\r\n<\/pre>\n<p>Since <strong>nums.map(x=&gt;x+1)<\/strong> returns a List, we don\u2019t have to name it to a variable to use it \u2014 we can just immediately use it, including doing another map function on it. (Of course, one could do this computation in a single go, e.g. map((x+1)*(x+1)), but often one is using a series of built-in functions, or functions one has predefined already).<\/p>\n<p>You can keep on mapping to your heart\u2019s content, including mapping from Ints to Strings.<\/p>\n<pre class=\"brush: scala;\">scala&gt; nums.map(x=&gt;x+1).map(x=&gt;x*x).map(x=&gt;x-1).map(x=&gt;x*(-1)).map(x=&gt;\"The answer is: \" + x)\r\nres12: List[java.lang.String] = List(The answer is: -3, The answer is: -8, The answer is: -15)\r\n<\/pre>\n<p>Note: the use of <em>x<\/em> in all these cases is not important. They could have been named <em>x, y, z<\/em> and <em>turlingdromes42<\/em> \u2014 any valid variable name.<\/p>\n<h2>         Iterating through multiple lists<\/h2>\n<p>Sometimes you have two lists that are paired up and you need to do something to elements from each list simultaneously. For example, let\u2019s say you have a list of word tokens and another list with their parts-of-speech. (See <a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/scala-tutorial-conditional-execution.html\">the previous tutorial<\/a> for discussion of parts-of-speech.)<\/p>\n<pre class=\"brush: scala;\">scala&gt; val tokens = List(\"the\", \"program\", \"halted\")\r\ntokens: List[java.lang.String] = List(the, program, halted)\r\n \r\nscala&gt; val tags = List(\"DT\",\"NN\",\"VB\")\r\ntags: List[java.lang.String] = List(DT, NN, VB)\r\n<\/pre>\n<p>Now, let\u2019s say we want to output these as the following string:<\/p>\n<p>the\/DT program\/NN halted\/VB<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Initially, we\u2019ll do it a step at a time, and then show how it can be done all in one line.<\/p>\n<p>First, we use the <strong>zip<\/strong> function to bring two lists together and get a new list of pairs of elements from each list.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val tokenTagPairs = tokens.zip(tags)\r\ntokenTagPairs: List[(java.lang.String, java.lang.String)] = List((the,DT), (program,NN), (halted,VB))\r\n \r\nZipping two lists together in this way is a common pattern used for iterating over two lists.\r\n \r\nNow we have a list of token-tag pairs we can use a for expression to turn it into a List of strings.\r\n \r\n1\r\nscala&gt; val tokenTagSlashStrings = for ((token, tag) &lt;- tokenTagPairs) yield token + \"\/\" + tag\r\ntokenTagSlashStrings: List[java.lang.String] = List(the\/DT, program\/NN, halted\/VB)\r\n<\/pre>\n<p>Now we just need to turn that list of strings into a single string by concatenating all its elements with a space between each. The function <strong>mkString<\/strong> makes this easy.<\/p>\n<pre class=\"brush: scala;\">scala&gt; tokenTagSlashStrings.mkString(\" \")\r\nres19: String = the\/DT program\/NN halted\/VB\r\n<\/pre>\n<p>Finally, here it all is in one step.<\/p>\n<pre class=\"brush: scala;\">scala&gt; (for ((token, tag) &lt;- tokens.zip(tags)) yield token + \"\/\" + tag).mkString(\" \")\r\nres23: String = the\/DT program\/NN halted\/VB\r\n<\/pre>\n<h2>         Ripping a string into a useful data structure<\/h2>\n<p>It is common in computational linguistics to need convert string inputs into useful data structures. Consider the part-of-speech tagged sentence mentioned in the previous tutorial. Let\u2019s begin by assigning it to the variable sentRaw.<\/p>\n<pre class=\"brush: scala;\">val sentRaw = \"The\/DT index\/NN of\/IN the\/DT 100\/CD largest\/JJS Nasdaq\/NNP financial\/JJ stocks\/NNS rose\/VBD modestly\/RB as\/IN well\/RB .\/.\"\r\n<\/pre>\n<p>Now, let\u2019s turn it into a List of Tuples, where each Tuple has the word as its first element and the postag as its second. We begin with the single line that does this so that you can see what the desired result is, and then we\u2019ll examine each step in detail.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val tokenTagPairs = sentRaw.split(\" \").toList.map(x =&gt; x.split(\"\/\")).map(x =&gt; Tuple2(x(0), x(1)))\r\ntokenTagPairs: List[(java.lang.String, java.lang.String)] = List((The,DT), (index,NN), (of,IN), (the,DT), (100,CD), (largest,JJS), (Nasdaq,NNP), (financial,JJ), (stocks,NNS), (rose,VBD), (modestly,RB), (as,IN), (well,RB), (.,.))\r\n<\/pre>\n<p>Let\u2019s take each of these in turn. The first <strong>split<\/strong> cuts <em>sentRaw<\/em> at each space character, and returns an Array of Strings, where each element is the material between the spaces.<\/p>\n<pre class=\"brush: scala;\">scala&gt; sentRaw.split(\" \")\r\nres0: Array[java.lang.String] = Array(The\/DT, index\/NN, of\/IN, the\/DT, 100\/CD, largest\/JJS, Nasdaq\/NNP, financial\/JJ, stocks\/NNS, rose\/VBD, modestly\/RB, as\/IN, well\/RB, .\/.)\r\n<\/pre>\n<p>What\u2019s an Array? It\u2019s a kind of sequence, like List, but it has some different properties that we\u2019ll discuss later. For now, let\u2019s stick with Lists, which we can do by using the <strong>toList<\/strong> method. Additionally, let\u2019s assign it to a variable so that the remaining operations are easier to focus on.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val tokenTagSlashStrings = sentRaw.split(\" \").toList\r\ntokenTagSlashStrings: List[java.lang.String] = List(The\/DT, index\/NN, of\/IN, the\/DT, 100\/CD, largest\/JJS, Nasdaq\/NNP, financial\/JJ, stocks\/NNS, rose\/VBD, modestly\/RB, as\/IN, well\/RB, .\/.)\r\n<\/pre>\n<p>Now, we need to turn each of the elements in that list into pairs of token and tag. Let\u2019s first consider a single element, turning something like \u201c<em>The\/DT<\/em>\u201d into the pair (<em>\u201cThe\u201d,\u201dDT\u201d)<\/em>. The next lines show how to do this one step at a time, using intermediate variables.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val first = \"The\/DT\"\r\nfirst: java.lang.String = The\/DT\r\n \r\nscala&gt; val firstSplit = first.split(\"\/\")\r\nfirstSplit: Array[java.lang.String] = Array(The, DT)\r\n \r\nscala&gt; val firstPair = Tuple2(firstSplit(0), firstSplit(1))\r\nfirstPair: (java.lang.String, java.lang.String) = (The,DT)\r\n<\/pre>\n<p>So, <em>firstPair<\/em> is a tuple representing the information encoded in the string first. This involved two operations, splitting and then creating a tuple from the Array that resulted from the split. We can do this for all of the elements in <em>tokenTagSlashStrings<\/em> using map. Let\u2019s first convert the Strings into Arrays.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val tokenTagArrays = tokenTagSlashStrings.map(x =&gt; x.split(\"\/\"))\r\nres0: List[Array[java.lang.String]] = List(Array(The, DT), Array(index, NN), Array(of, IN), Array(the, DT), Array(100, CD), Array(largest, JJS), Array(Nasdaq, NNP), Array(financial, JJ), Array(stocks, NNS), Array(rose, VBD), Array(modestly, RB), Array(as, IN), Array(well, RB), Array(., .))\r\n<\/pre>\n<p>And finally, we turn the Arrays into Tuple2s and get the result we obtained with the one-liner earlier.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val tokenTagPairs = tokenTagArrays.map(x =&gt; Tuple2(x(0), x(1)))\r\ntokenTagPairs: List[(java.lang.String, java.lang.String)] = List((The,DT), (index,NN), (of,IN), (the,DT), (100,CD), (largest,JJS), (Nasdaq,NNP), (financial,JJ), (stocks,NNS), (rose,VBD), (modestly,RB), (as,IN), (well,RB), (.,.))\r\n<\/pre>\n<p><em>Note<\/em>: if you are comfortable with using one-liners that chain a bunch of operations together, then by all means use them. However, there is no shame in using several lines involving a bunch of intermediate variables if that helps you break apart the task and get the result you need.<\/p>\n<p>One of the very useful things of having a List of pairs (Tuple2s) is that the <strong>unzip<\/strong> function gives us back two Lists, one with all of the first elements and another with all of the second elements.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val (tokens, tags) = tokenTagPairs.unzip\r\ntokens: List[java.lang.String] = List(The, index, of, the, 100, largest, Nasdaq, financial, stocks, rose, modestly, as, well, .)\r\ntags: List[java.lang.String] = List(DT, NN, IN, DT, CD, JJS, NNP, JJ, NNS, VBD, RB, IN, RB, .)\r\n<\/pre>\n<p>With this, we\u2019ve come full circle. Having started with a raw string (such as we are likely to read in from a text file), we now have Lists that allow us to do useful computations, such as converting those tags into another form.<\/p>\n<h2>         Providing a function you have defined to map<\/h2>\n<p>Let\u2019s return to the postag simplification exercise we did in the previous tutorial. We\u2019ll modify it a bit: rather than shortening the Penn Treebank parts-of-speech, let\u2019s convert them to course parts-of-speech using the English words that most people are familiar with, like noun and verb. The following function turns Penn Treebank tags into these course tags, for more tags than we covered in the last tutorial (note: this is still incomplete, but serves to illustrate the point).<\/p>\n<pre class=\"brush: scala;\">def coursePos (tag: String) = tag match {\r\n  case \"NN\" | \"NNS\" | \"NNP\" | \"NNPS\"                       =&gt; \"Noun\"\r\n  case \"JJ\" | \"JJR\" | \"JJS\"                                =&gt; \"Adjective\"\r\n  case \"VB\" | \"VBD\" | \"VBG\" | \"VBN\" | \"VBP\" | \"VBZ\" | \"MD\" =&gt; \"Verb\"\r\n  case \"RB\" | \"RBR\" | \"RBS\" | \"WRB\" | \"EX\"                 =&gt; \"Adverb\"\r\n  case \"PRP\" | \"PRP$\" | \"WP\" | \"WP$\"                       =&gt; \"Pronoun\"\r\n  case \"DT\" | \"PDT\" | \"WDT\"                                =&gt; \"Article\"\r\n  case \"CC\"                                                =&gt; \"Conjunction\"\r\n  case \"IN\" | \"TO\"                                         =&gt; \"Preposition\"\r\n  case _                                                   =&gt; \"Other\"\r\n}\r\n<\/pre>\n<p>We can now map this function over the parts of speech in the collection obtained previously.<\/p>\n<pre class=\"brush: scala;\">scala&gt; tags.map(coursePos)\r\nres1: List[java.lang.String] = List(Article, Noun, Preposition, Article, Other, Adjective, Noun, Adjective, Noun, Verb, Adverb, Preposition, Adverb, Other)\r\n<\/pre>\n<p>Voila! If we want to convert the tags in this manner and then output them as a string like what we started with, it\u2019s just a few steps. We\u2019ll start from the beginning and recap. Try running the following for yourself.<\/p>\n<pre class=\"brush: scala;\">val sentRaw = \"The\/DT index\/NN of\/IN the\/DT 100\/CD largest\/JJS Nasdaq\/NNP financial\/JJ stocks\/NNS rose\/VBD modestly\/RB as\/IN well\/RB .\/.\"\r\n \r\nval (tokens, tags) = sentRaw.split(\" \").toList.map(x =&gt; x.split(\"\/\")).map(x =&gt; Tuple2(x(0), x(1))).unzip\r\n \r\ntokens.zip(tags.map(coursePos)).map(x =&gt; x._1+\"\/\"+x._2).mkString(\" \")\r\n<\/pre>\n<p>A further point is that when you provide expressions like <strong>(x =&gt; x+1)<\/strong> to <strong>map<\/strong>, you are actually defining an anonymous function! Here is the same map operation with different levels of specification<\/p>\n<pre class=\"brush: scala;\">scala&gt; val numbers = (1 to 5).toList\r\nnumbers: List[Int] = List(1, 2, 3, 4, 5)\r\n \r\nscala&gt; numbers.map(1+)\r\nres11: List[Int] = List(2, 3, 4, 5, 6)\r\n \r\nscala&gt; numbers.map(_+1)\r\nres12: List[Int] = List(2, 3, 4, 5, 6)\r\n \r\nscala&gt; numbers.map(x=&gt;x+1)\r\nres13: List[Int] = List(2, 3, 4, 5, 6)\r\n \r\nscala&gt; numbers.map((x: Int) =&gt; x+1)\r\nres14: List[Int] = List(2, 3, 4, 5, 6)\r\n<\/pre>\n<p>So, it\u2019s all consistent: whether you pass in a named function or an anonymous function, <strong>map<\/strong> will apply it to each element in the list.<\/p>\n<p>Finally, note that you can use that final form to define a function.<\/p>\n<pre class=\"brush: scala;\">scala&gt; def addOne = (x: Int) =&gt; x + 1\r\naddOne: (Int) =&gt; Int\r\n \r\nscala&gt; addOne(1)\r\nres15: Int = 2\r\n<\/pre>\n<p>This is similar to defining functions as we had previously (e.g. <strong>def addOne (x: Int) = x+1<\/strong>), but it is more convenient in certain contexts, which we\u2019ll get to later. For now, the thing to realize is that whenever you map, you are either using a function that already existed or creating one on the fly.<\/p>\n<h2>         Filtering and counting<\/h2>\n<p>The <strong>map<\/strong> method is a convenient way of performing computations on each element of a List, effectively transforming a List from one set of values to a new List with a set of values computed from each corresponding element. There are yet more methods that have other actions, such as removing elements from a List (<strong>filter<\/strong>), counting the number of elements satisfying a given predicate (<strong>count<\/strong>), and computing an aggregate single result from all elements in a List (<strong>reduce<\/strong> and <strong>fold<\/strong>). Let\u2019s consider a simple task: count how many tokens are <em>not<\/em> a noun or adjective in a tagged sentence. As a starting point, let\u2019s take the list of mapped postags from before.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val courseTags = tags.map(coursePos)\r\ncourseTags: List[java.lang.String] = List(Article, Noun, Preposition, Article, Other, Adjective, Noun, Adjective, Noun, Verb, Adverb, Preposition, Adverb, Other)\r\n<\/pre>\n<p>One way of doing this is to filter out all of the nouns and adjectives to obtain a list without them and then get its length.<\/p>\n<pre class=\"brush: scala;\">scala&gt; val noNouns = courseTags.filter(x =&gt; x != \"Noun\")noNouns: List[java.lang.String] = List(Article, Preposition, Article, Other, Adjective, Adjective, Verb, Adverb, Preposition, Adverb, Other)\r\n \r\nscala&gt; val noNounsOrAdjectives = noNouns.filter(x =&gt; x != \"Adjective\")\r\nnoNounsOrAdjectives: List[java.lang.String] = List(Article, Preposition, Article, Other, Verb, Adverb, Preposition, Adverb, Other)\r\n \r\nscala&gt; noNounsOrAdjectives.length\r\nres8: Int = 9\r\n<\/pre>\n<p>However, because <strong>filter<\/strong> just takes a Boolean value, we can of course use Boolean conjunction and disjunction to simplify things. And, we don\u2019t need to save intermediate variables. Here\u2019s the one liner.<\/p>\n<pre class=\"brush: scala;\">scala&gt; courseTags.filter(x =&gt; x != \"Noun\" &amp;&amp; x != \"Adjective\").length\r\nres9: Int = 9\r\n<\/pre>\n<p>If all we want is the number of elements, we can instead just use <strong>count<\/strong> with the same predicate.<\/p>\n<pre class=\"brush: scala;\">scala&gt; courseTags.count(x =&gt; x != \"Noun\" &amp;&amp; x != \"Adjective\")\r\nres10: Int = 9\r\n<\/pre>\n<p>As an exercise, try doing a one-liner that starts with <em>sentRaw<\/em> and provides the value \u201c<strong>resX: Int = 9<\/strong>\u201d (where <em>X<\/em> is whatever you get in your Scala REPL).<\/p>\n<p>In the next tutorial, we\u2019ll see how to use <strong>reduce<\/strong> and <strong>fold<\/strong> to compute aggregate results from a List.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/bcomposes.wordpress.com\/2011\/08\/30\/first-steps-in-scala-for-beginning-programmers-part-4\/\">First steps in Scala for beginning programmers, Part 4<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Jason Baldridge at the <a href=\"http:\/\/bcomposes.wordpress.com\/\">Bcomposes<\/a> blog.<\/p>\n<p><strong><i>Related Articles :<\/i><\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/scala-tutorial-scala-repl-expressions.html\">Scala Tutorial &#8211; Scala REPL, expressions, variables, basic types, simple functions, saving and running programs, comments<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/scala-tutorial-tuples-lists-methods-on.html\">Scala Tutorial &#8211; Tuples, Lists, methods on Lists and Strings<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/scala-tutorial-conditional-execution.html\">Scala Tutorial &#8211; conditional execution with if-else blocks and matching<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-regular-expressions.html\">Scala Tutorial &#8211; regular expressions, matching<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-regular-expressions_05.html\">Scala Tutorial &#8211; regular expressions, matching and substitutions with the scala.util.matching API<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-maps-sets-groupby.html\">Scala Tutorial &#8211; Maps, Sets, groupBy, Options, flatten, flatMap<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-scalaiosource-accessing.html\">Scala Tutorial &#8211; scala.io.Source, accessing files, flatMap, mutable Maps<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-objects-classes.html\">Scala Tutorial &#8211; objects, classes, inheritance, traits, Lists with multiple related types, apply<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-scripting-compiling-main.html\">Scala Tutorial &#8211; scripting, compiling, main methods, return values of functions<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/scala-tutorial-sbt-scalabha-packages.html\">Scala Tutorial &#8211; SBT, scalabha, packages, build systems<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/scala-tutorial-code-blocks-coding-style.html\">Scala Tutorial &#8211; code blocks, coding style, closures, scala documentation project<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/fun-with-function-composition-in-scala.html\">Fun with function composition in Scala<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/how-scala-changed-way-i-think-about-my.html\">How Scala changed the way I think about my Java Code<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/what-features-of-java-have-been-dropped.html\">What features of Java have been dropped in Scala?<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/testing-with-scala.html\">Testing with Scala<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/12\/things-every-programmer-should-know.html\">Things Every Programmer Should Know<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Preface This is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other resources on the links page of the Computational Linguistics course I\u2019m creating these for. Additionally you can find this and other tutorial series on the JCG Java &hellip;<\/p>\n","protected":false},"author":67,"featured_media":227,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[235],"class_list":["post-651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scala","tag-scala-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scala Tutorial - iteration, for expressions, yield, map, filter, count - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"PrefaceThis is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Tutorial - iteration, for expressions, yield, map, filter, count - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"PrefaceThis is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-10-03T21:58:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:33:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jason Baldridge\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/jasonbaldridge\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason Baldridge\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html\"},\"author\":{\"name\":\"Jason Baldridge\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/95ef2670a4040b0f7101c48dba2795c0\"},\"headline\":\"Scala Tutorial &#8211; iteration, for expressions, yield, map, filter, count\",\"datePublished\":\"2011-10-03T21:58:00+00:00\",\"dateModified\":\"2012-10-21T20:33:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html\"},\"wordCount\":1965,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"keywords\":[\"Scala Tutorial\"],\"articleSection\":[\"Scala\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html\",\"name\":\"Scala Tutorial - iteration, for expressions, yield, map, filter, count - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"datePublished\":\"2011-10-03T21:58:00+00:00\",\"dateModified\":\"2012-10-21T20:33:04+00:00\",\"description\":\"PrefaceThis is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/scala-tutorial-iteration-for.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/jvm-languages\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Scala\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/jvm-languages\\\/scala\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Scala Tutorial &#8211; iteration, for expressions, yield, map, filter, count\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/95ef2670a4040b0f7101c48dba2795c0\",\"name\":\"Jason Baldridge\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b755d282f869512990e0ce9118c71ccd859fad42163f8e5d62d180ea42ea9720?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b755d282f869512990e0ce9118c71ccd859fad42163f8e5d62d180ea42ea9720?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b755d282f869512990e0ce9118c71ccd859fad42163f8e5d62d180ea42ea9720?s=96&d=mm&r=g\",\"caption\":\"Jason Baldridge\"},\"sameAs\":[\"http:\\\/\\\/bcomposes.wordpress.com\\\/\",\"http:\\\/\\\/www.linkedin.com\\\/pub\\\/jason-baldridge\\\/5\\\/629\\\/9b2\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/twitter.com\\\/jasonbaldridge\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/jason-baldridge\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Tutorial - iteration, for expressions, yield, map, filter, count - Java Code Geeks","description":"PrefaceThis is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html","og_locale":"en_US","og_type":"article","og_title":"Scala Tutorial - iteration, for expressions, yield, map, filter, count - Java Code Geeks","og_description":"PrefaceThis is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other","og_url":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-10-03T21:58:00+00:00","article_modified_time":"2012-10-21T20:33:04+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","type":"image\/jpeg"}],"author":"Jason Baldridge","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/jasonbaldridge","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Jason Baldridge","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html"},"author":{"name":"Jason Baldridge","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/95ef2670a4040b0f7101c48dba2795c0"},"headline":"Scala Tutorial &#8211; iteration, for expressions, yield, map, filter, count","datePublished":"2011-10-03T21:58:00+00:00","dateModified":"2012-10-21T20:33:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html"},"wordCount":1965,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","keywords":["Scala Tutorial"],"articleSection":["Scala"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html","url":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html","name":"Scala Tutorial - iteration, for expressions, yield, map, filter, count - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","datePublished":"2011-10-03T21:58:00+00:00","dateModified":"2012-10-21T20:33:04+00:00","description":"PrefaceThis is part 4 of tutorials for first-time programmers getting into Scala. Other posts are on this blog, and you can get links to those and other","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/scala-tutorial-iteration-for.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/www.javacodegeeks.com\/category\/jvm-languages"},{"@type":"ListItem","position":3,"name":"Scala","item":"https:\/\/www.javacodegeeks.com\/category\/jvm-languages\/scala"},{"@type":"ListItem","position":4,"name":"Scala Tutorial &#8211; iteration, for expressions, yield, map, filter, count"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/95ef2670a4040b0f7101c48dba2795c0","name":"Jason Baldridge","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b755d282f869512990e0ce9118c71ccd859fad42163f8e5d62d180ea42ea9720?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b755d282f869512990e0ce9118c71ccd859fad42163f8e5d62d180ea42ea9720?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b755d282f869512990e0ce9118c71ccd859fad42163f8e5d62d180ea42ea9720?s=96&d=mm&r=g","caption":"Jason Baldridge"},"sameAs":["http:\/\/bcomposes.wordpress.com\/","http:\/\/www.linkedin.com\/pub\/jason-baldridge\/5\/629\/9b2","https:\/\/x.com\/http:\/\/twitter.com\/jasonbaldridge"],"url":"https:\/\/www.javacodegeeks.com\/author\/jason-baldridge"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/67"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/227"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}