I am trying to learn Scala and try to write the understanding of the sequence, which is the sequence, Removes the tragrum. For example, [1,2,3,4] should be transformed (not Scala syntax)
[1; _, 1; _, _, 1; 2; 1,2; _, 1,2; 3; 2,3; 1,2,3; 4; 3,4; 2,3,4] DRF trigger (token: sec [t]) = {var t1: option [t] = any version T2: Option [T] = None (T3 and LT; - Token) {yield yield T3 (T2, T3) yield (T1, T2, some (T3)) T1 = T 2 T2 = T3}}
but it does not compile, only one yield to for --comprehension Permission is granted (no block statement). Is there any other great way to get the same behavior with only one pass on the data? You can not have many yields in the loop because the syntax for loop mat (or flatmap) is Chinese:
for translation (i & lt; - collection) yield (throw (i))
Collection Map {i = & gt; (I & lt; - archive) for func (i)
Translation
Collection leading {i = & gt; Func (i)} Therefore the entire body of the loop has been changed to one stop, and yield determines the keyword The function that is called on the collection is map or foreach (or flatMap ).
- Using compulsory statements next to a
yieldwhich will be determined. - The yield
(Not to mention that your proposed Varrison will return a list [any] because tuples and 1 gram are of all types Instead of wanting to get a list [list [int]]
instead try the following (which put the n-gram visible in sequence ):
val base = list (1,2,3,4) wall sliding separators = 1 to 4 map (base sliding _) {for onegram < Edge ngram & lt; - slidingIterators if ngram.hasNext} yield (ngram .next) or
val base = list (1,2,3) , 4) Wall slidingcutters = 1 to 4 map (base sliding _) val first = sliding eaters head val buff = new listbuffer [list] for [i.htc] - (i.hasNext) while (first laugh next) I.hasNext) buf + = i.next If you prefer the N-grams in the order of length, try:
val base = List (1,2,3,4) 1 to 4 FlatMap {Base Sliding _ toList}
Comments
Post a Comment