![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
scala
迷途小码
大数据及后台开发 python|scala|c|java|go
展开
-
Scala:根据key分组取top n
package com.dk.spark.algo.topnimport com.dk.spark.context.SparkContextManagerimport org.apache.spark.rdd.RDD/** * Created by Divakant Pandey on 5/29/17. */object TopNByKeys { val N = 2 ...转载 2019-11-18 10:02:25 · 681 阅读 · 0 评论 -
Scala:通过key或者value排序Map(sortBy, sortWith)
sort the map by key, from low to high, usingsortBy:scala> import scala.collection.immutable.ListMapimport scala.collection.immutable.ListMapscala> ListMap(grades.toSeq.sortBy(_._1):_*)r...转载 2019-11-18 09:48:28 · 2096 阅读 · 0 评论 -
Scala: 合并两个Map
Solution1: foldLeftscala> val merged = (m1 /: m2) { case (map, (k,v)) => map + ( k -> (v + map.getOrElse(k, 0)) ) }merged: scala.collection.immutable.Map[Int,Int] = Map(1...转载 2019-11-17 21:15:37 · 375 阅读 · 0 评论 -
scala隐式参数(implicit)
转自:http://criss.iteye.com/blog/1806515========================================SBinary 和 Scalacheck的一部分库,广泛使用了隐式参数。让人联想起了Haskell(一种函数式编程语言)的编程风格,我真心的希望在Scala中这种编程风格更加广泛。这是一种非常有用的技术。作为开始如下多重入参(柯转载 2016-06-21 08:47:15 · 759 阅读 · 0 评论