我只是想知道我们怎么知道哪些函数需要括号()而哪些函数不需要?例如
replicate 100 (product (map (*3) (zipWith max [1,2,3,4,5] [4,5,6,7,8])))
Run Code Online (Sandbox Code Playgroud)
工作良好.但
replicate 100 (product (map (*3) (zipWith (max [1,2,3,4,5] [4,5,6,7,8]))))
Run Code Online (Sandbox Code Playgroud)
不起作用.这是因为我为zipWith添加了一组括号.在这个小例子中,zipWith和max没有括号,但是复制,产品和地图都有.一般来说,有一种方法可以知道/确定哪些功能需要括号,哪些功能不需要.
我正在Hive中学习简单的正则表达式.我正在按照教程和简单的hql语句获取错误?
select REGEXP_EXTRACT( 'Hello, my name is Ben. Please visit' , 'Ben' )
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误消息:
Wrong arguments ''Ben'': org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public java.lang.String org.apache.hadoop.hive.ql.udf.UDFRegExpExtract.evaluate(java.lang.String,java.lang.String) on object org.apache.hadoop.hive.ql.udf.UDFRegExpExtract@ec0c06f of class org.apache.hadoop.hive.ql.udf.UDFRegExpExtract with arguments {Hello, my name is Ben. Please visit:java.lang.String, Ben:java.lang.String} of size 2
它适用于其他语言,但我想在Hive中学习它.任何帮助,将不胜感激.
我在Haskell中经历了groupBy,我理解的是groupBy函数接受List和条件,并根据指定的条件对元素进行分组.
let value = [-3,-5,-1,1,1,1,2,3,-1,-2]
groupBy (\x y -> (x > 0) == (y > 0)) value
Run Code Online (Sandbox Code Playgroud)
它工作正常,但为什么我们应该在lambda函数中给出两个变量?为什么"groupBy(> 0)值"不起作用?两个条件都应该相同吗?如果它们不同会发生什么.请举例说明.
我正在尝试执行此功能
def sumofdouble[T <:Number] (as:T*): Double = as.foldLeft(0d)(_ + _.doubleValue)
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用这样的功能,
sumofdouble(1,2)
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
<console>:13: error: inferred type arguments [Int] do not conform to method sumofdouble's type parameter bounds [T <: Number]
sumofdouble(1,2)
Run Code Online (Sandbox Code Playgroud)
整数不是Number的子类型吗?请解释我是否遗漏了一些东西.
map和flatMap有什么区别?因为在我们可以做到
1 to 5 map(c => println(c))
Run Code Online (Sandbox Code Playgroud)
但不是
1 to 5 flatMap(c => println(c))
Run Code Online (Sandbox Code Playgroud)
另一方面,这是有效的
def h(i: Int) = if (i >= 2) Some(i) else None
1 to 5 flatMap(h)
Run Code Online (Sandbox Code Playgroud)
我知道flatMap是map和flatten,但不确定何时可以使用map并且可以使用flatMap.
我的功能是
val f2 : (String, String) => Int = new Function2[String, String, Int] {
def apply(s1 : String, s2 : String) = s1.length + s2.length
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能在Scala中这样做
val listOfFullNames = List(("Mark","Smith"), ("Jim","Duggan"), ("Eddie","Murphy"), ("Sylvester","Stallone"))
val output3 = listOfFullNames.map(f2)
Run Code Online (Sandbox Code Playgroud)
错误消息很有意思,它说预期:(String,String)=> TypeInferredB,但是real(String,String)=> Int
//But this works fine
val output3 = listOfFullNames.map(x => f2(x._1, x._2))
Run Code Online (Sandbox Code Playgroud)
我这样做的原因纯粹是因为,这是有效的
val f :String => Int = new Function[String, Int] {
def apply(s : String) = s.length
}
Run Code Online (Sandbox Code Playgroud)
这可以这样使用
val listOfNames = List("Mark", "Jim", "Eddie", "Sylvester","Stallone")
val output …Run Code Online (Sandbox Code Playgroud) 有什么区别
dotEx1 = map(+3) . filter (>100)
Run Code Online (Sandbox Code Playgroud)
和
dotEx1 xs = map(+3) . filter (>100) xs
Run Code Online (Sandbox Code Playgroud)
以来
myFilter xs = filter (>100) xs
Run Code Online (Sandbox Code Playgroud)
和
myFilter = filter (>100)
Run Code Online (Sandbox Code Playgroud)
是不一样的原因
dotEx1 = map(+3) . filter (>100)
Run Code Online (Sandbox Code Playgroud)
和
dotEx1 xs = map(+3) . filter (>100) xs
Run Code Online (Sandbox Code Playgroud)
相同?
在 Prelude 中,取消线路按预期工作。下面是例子
GHCi>unlines ["aa","bb","bb"]
"aa\nbb\nbb\n"
Run Code Online (Sandbox Code Playgroud)
但为什么线路不起作用。甚至类型签名也表明它只能接受数字。
GHCi>:t lines
lines :: Num t => [t]
Run Code Online (Sandbox Code Playgroud)
所以,如果我尝试
GHCi>lines "aa\nbb\nbb\n"
Run Code Online (Sandbox Code Playgroud)
为什么我会收到错误消息?是否有我需要导入的行?
问候,
请在Scala中对此进行解释。
如果我有一个
trait A
Run Code Online (Sandbox Code Playgroud)
我不能做
val a = new A
Run Code Online (Sandbox Code Playgroud)
但是这个特质
trait DS[-In, +Out]{def apply(i: In): Out}
Run Code Online (Sandbox Code Playgroud)
可以有一个实例
val t1 = new DS[Any, Int]{def apply(i: Any) = i.toString.toInt}
Run Code Online (Sandbox Code Playgroud)
如何允许?
我正在阅读有关scalatest的内容,而且我很多时候都会遇到这种语法
trait Sample {
self : FlatSpec =>
}
Run Code Online (Sandbox Code Playgroud)
这是什么意思?请举例说明
如果我有这样的课程
class CanFlyType[T <: {type thing <: Bird}](t : T) {
def flySpeed() = {
println(t)
}
}
Run Code Online (Sandbox Code Playgroud)
你可以在构造函数中传递什么来创建这个类?我试过传递这个
class Species
class Animal extends Species
class Tiger extends Animal
abstract class Bird (name : String) extends Species {
val birdName = name
val flySpeed : Int
}
class Sparrow(name : String) extends Bird(name) {
val flySpeed = 30
}
val sparrow : Bird1 = new Sparrow("Robbin")
val canFly = new CanFlyType(sparrow)
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误.我知道我们可以通过其他方式实现这一点,但我只是想知道你是否可以在结构类型方式中使用类型以及上面和
class CanFly1[T <: Bird1](bird : T) {
def …Run Code Online (Sandbox Code Playgroud) 假设我有一个这样的数据框
val customer = Seq(
("C1", "Jackie Chan", 50, "Dayton", "M"),
("C2", "Harry Smith", 30, "Beavercreek", "M"),
("C3", "Ellen Smith", 28, "Beavercreek", "F"),
("C4", "John Chan", 26, "Dayton","M")
).toDF("cid","name","age","city","sex")
Run Code Online (Sandbox Code Playgroud)
我怎样才能在一列中获得 cid 值并array < struct < column_name, column_value > >在火花中获得其余的值