seq

Implicit definition working for Seq but not for Set

元气小坏坏 提交于 2019-12-11 14:49:22
问题 So I've made some utility classes and implicit conversions for them. However, it works fine when converting from a Seq but not from a Set, although the code is the same, and those two traits seem rather similar at first sight. What could be the problem, and how would I fix it? import scala.collection.mutable.HashMap trait Indexed[T] { def index: T } class IndexMap[T, V <: Indexed[T]] extends HashMap[T, V] { override def put(key: T, value: V): Option[V] = { require(key == value.index) super

missing hour in seq function generating time in R?

拜拜、爱过 提交于 2019-12-11 12:48:35
问题 I have a problem in generating proper time sequence using R: fivemin <- seq(as.POSIXct("2014/01/01 0:00:00"), as.POSIXct("2014/04/01 0:00:00"), by="5 mins",tz="EST") time <- data.frame(MasterTime=fivemin) Using above code, I can get a data frame with 25909 observations. However, under Eastern Standard Time (without daylight saving), the number of observations should be 25920. The difference is 1 hour from the transition of daylight saving time on 03/09/20014, because then the time would

Use `seq` and print in haskell

此生再无相见时 提交于 2019-12-11 07:32:33
问题 I know that this is a little bit tricky but i wonder why it doesn't work! module Main where sillyDebug :: Int -> Int -> Int sillyDebug x y = (print x) `seq` (x + y) main :: IO () main = do print (sillyDebug 1 2) while its ideal is the same as sillyDebug = (trace (show x) False) `seq` (x + y) Is it related to lazy evaluation or side effect in haskell? https://hackhands.com/lazy-evaluation-works-haskell/ 回答1: Merely evaluating some IO action doesn’t do anything at all. You can think of IO sort

convert List[Tuple2[A,B]] to Tuple2[Seq[A],Seq[B]]

时光总嘲笑我的痴心妄想 提交于 2019-12-11 01:40:59
问题 Stuck here, trying to convert a List of case class tuples to a tuple of sequences and multi-assign the result. val items = repo.foo.list // gives me a List[(A,B)] I can pull off multi-assignment like so: val(a,b) = (items.map(_._1).toSeq, items.map(_._2).toSeq) but it would be nicer to do in 1 step, along the lines of: val(a,b) = repo.foo.list.map{case(a,b) => (a,b)} 回答1: I am not sure if I understood the question correctly. Maybe unzip works for what you want? Here is a link with some

Add element to Seq[String] in Scala

妖精的绣舞 提交于 2019-12-10 21:39:36
问题 I'm trying to create a list of words in Scala. I'm new to the language. I have read a lot of posts about how you can't edit immutable objects, but none that has managed to show me how to create the list I need in Scala. I am using var to initialise, but this isn't helping. var wordList = Seq.empty[String] for (x <- docSample.tokens) { wordList.++(x.word) } println(wordList.isEmpty) I would greatly appreciate some help with this. I understand that objects are immutable in Scala (although vars

Add an index (or counter) to a dataframe by group in R [duplicate]

给你一囗甜甜゛ 提交于 2019-12-10 16:39:06
问题 This question already has answers here : Numbering rows within groups in a data frame (6 answers) Closed 3 years ago . I have a df like ProjectID Dist 1 x 1 y 2 z 2 x 2 h 3 k .... .... I want to add a third column such that we have an incrementing counter for each ProjectID: ProjectID Dist counter 1 x 1 1 y 2 2 z 1 2 x 2 2 h 3 1 k 3 .... .... I've had a look at seq rank and a couple of other bits particularly looking to see if I could use ddply to help: df$counter <- ddply(df,.(projectID),

Type inference in sequence expressions in F#

二次信任 提交于 2019-12-10 03:01:02
问题 I think I do not quite understand how F# infers types in sequence expressions and why types are not correctly recognized even if I specify the type of the elements directly from "seq". In the following F# code we have a base class A and two derived classes, B and C: type A(x) = member a.X = x type B(x) = inherit A(x) type C(x) = inherit A(x) If I try to "yield" their instances in a simple sequence expressions, I get two errors: // Doesn't work, but it makes sense. let testSeq = seq { yield A

R rep seq where number of rows is not multiple of seq length

余生颓废 提交于 2019-12-09 01:42:53
问题 I have a data frame with 1666 rows. I would like to add a column with a repeating sequence of 1:5 to use with cut() to do cross validation. It would look like this: Y x1 x2 Id1 1 .15 3.6 1 0 1.1 2.2 2 0 .05 3.3 3 0 .45 2.8 4 1 .85 3.1 5 1 1.01 2.9 1 ... ... ... ... I've tried the following 2 ways but get an error message as it seems to only add numbers in increments of the full seq() argument: > tr2$Id1 <- rep(seq(1,5,1), (nrow(tr2)/5)) Error in `$<-.data.frame`(`*tmp*`, "Id", value = c(1, 2,

F#: how to evaluate a “seq” to get all its values eagerly?

淺唱寂寞╮ 提交于 2019-12-08 17:35:58
问题 We know that in F#, seq is lazy evaluated. My question is, if I have a seq with limited number of values, how to convert it into some data type that contains all its value evaluated? > seq { for i in 1 .. 10 do yield i * i };; val it : seq<int> = seq [1; 4; 9; 16; ...] Thanks a lot. 回答1: The answer from @Carsten is correct: you can use Seq.toArray or Seq.toList if you wish to convert lazily evaluated sequences to lists or arrays. Don't use these function to force evaluation, though. The most

Why can't I force an IO action with seq?

无人久伴 提交于 2019-12-08 17:07:41
问题 Given this code snippet: someFunction x = print x `seq` 1 main = do print (someFunction "test") why doesn't the print x print test when the code is executed? $./seq_test 1 If I replace it with error I can check that the left operand of seq is indeed evaluated. How could I achieve my expected output: test 1 modifying only someFunction ? 回答1: Evaluating an IO action does nothing whatsoever. That's right! If you like, values of IO type are merely "instruction lists". So all you do with that seq