Clump 多源数据组合开源项目

我要开发同款
匿名用户2015年05月12日
42阅读
开发技术Scala
所属分类常用工具包、程序开发
授权协议Apache

作品详情

Clump是一个Scala库,通过一个优雅和高效的方式将来自多个源的数据组合在一起。

例如:

import io.getclump.Clump// Creates sources using the batched interfacesval tracksSource = Clump.source(tracksService.fetch _)(_.id)val usersSource = Clump.source(usersService.fetch _)(_.id)def renderTrackPosts(userId: Long) = {  // Defines the clump  val clump: Clump[List[EnrichedTrack]] = enrichedTrackPosts(userId)  // Triggers execution  val future: Future[Option[List[EnrichedTrack]]] = clump.get  // Renders the response  future.map {    case Some(trackPosts) => render.json(trackPosts)    case None             => render.notFound  }}// Composes a clump with the user's track postsdef enrichedTrackPosts(userId: Long) =  for {    trackPosts <- Clump.future(timelineService.fetchTrackPosts(userId))    enrichedTracks <- Clump.traverse(trackPosts)(enrichedTrack(_))  } yield {    enrichedTracks  }// Composes an enriched track clumpdef enrichedTrack(trackId: Long) =  for {    track <- tracksSource.get(trackId)    creator <- usersSource.get(track.creatorId)  } yield {    new EnrichedTrack(track, creator)  }
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论