Haskell语言学习笔记(75)Conduit
安装 conduit
$ cabal install conduit
Installed conduit-1.3.0.3
Prelude> import Conduit
Prelude Conduit>
Conduit
Conduit 是一个处理流的库。
Prelude Conduit> :{
Prelude Conduit| print $ runConduitPure
$ yieldMany [1..10]
.| mapC (+ 1)
.| sinkList
Prelude Conduit| :}
[2,3,4,5,6,7,8,9,10,11]
应用实例
{-# LANGUAGE ExtendedDefaultRules #-}
import Conduit
magic :: Int -> IO Int
magic x = do
putStrLn $ "I'm doing magic with " ++ show x
return $ x * 2
main :: IO ()
main = do
putStrLn "List version:"
mapM magic (take 10 [1..]) >>= mapM_ print . takeWhile (< 18)
putStrLn ""
putStrLn "Conduit version:"
runConduit
$ yieldMany [1..]
.| takeC 10
.| mapMC magic
.| takeWhileC (< 18)
.| mapM_C print
List version:
I'm doing magic with 1
I'm doing magic with 2
I'm doing magic with 3
I'm doing magic with 4
I'm doing magic with 5
I'm doing magic with 6
I'm doing magic with 7
I'm doing magic with 8
I'm doing magic with 9
I'm doing magic with 10
2
4
6
8
10
12
14
16
Conduit version:
I'm doing magic with 1
2
I'm doing magic with 2
4
I'm doing magic with 3
6
I'm doing magic with 4
8
I'm doing magic with 5
10
I'm doing magic with 6
12
I'm doing magic with 7
14
I'm doing magic with 8
16
I'm doing magic with 9
Haskell语言学习笔记(75)Conduit的更多相关文章
- Haskell语言学习笔记(88)语言扩展(1)
ExistentialQuantification {-# LANGUAGE ExistentialQuantification #-} 存在类型专用的语言扩展 Haskell语言学习笔记(73)Ex ...
- Haskell语言学习笔记(79)lambda演算
lambda演算 根据维基百科,lambda演算(英语:lambda calculus,λ-calculus)是一套从数学逻辑中发展,以变量绑定和替换的规则,来研究函数如何抽象化定义.函数如何被应用以 ...
- Haskell语言学习笔记(69)Yesod
Yesod Yesod 是一个使用 Haskell 语言的 Web 框架. 安装 Yesod 首先更新 Haskell Platform 到最新版 (Yesod 依赖的库非常多,版本不一致的话很容易安 ...
- Haskell语言学习笔记(20)IORef, STRef
IORef 一个在IO monad中使用变量的类型. 函数 参数 功能 newIORef 值 新建带初值的引用 readIORef 引用 读取引用的值 writeIORef 引用和值 设置引用的值 m ...
- Haskell语言学习笔记(39)Category
Category class Category cat where id :: cat a a (.) :: cat b c -> cat a b -> cat a c instance ...
- Haskell语言学习笔记(85)Async
安装 async $ cabal install async async-2.2.1 installed async / wait / concurrently async :: IO a -> ...
- Haskell语言学习笔记(72)Free Monad
安装 free 包 $ cabal install free Installed free-5.0.2 Free Monad data Free f a = Pure a | Free (f (Fre ...
- Haskell语言学习笔记(44)Lens(2)
自定义 Lens 和 Isos -- Some of the examples in this chapter require a few GHC extensions: -- TemplateHas ...
- Haskell语言学习笔记(38)Lens(1)
Lens Lens是一个接近语言级别的库,使用它可以方便的读取,设置,修改一个大的数据结构中某一部分的值. view, over, set Prelude> :m +Control.Lens P ...
随机推荐
- 第6章 静态路由和动态路由(3)_RIP动态路由协议
5. RIP动态路由协议 5.1 RIP协议(Routing Information Protocol) (1)是一个距离矢量路由选择协议.选择最佳路径的标准是跳数,如果到达目标网络经过的路由器最少, ...
- 10 sed命令的基本用法
grep灵活的关联正则表达式实现文件过滤,而sed是一个数据流的编辑器,或者说是一个行编辑器,它将文件一行一行的数据放入到内存中进行编辑,而awk是一个报告生成器,这个我们以后再说: 之前我们介绍过g ...
- Css实战第二天小结
清除浮动的四种方式: 1.1 给父盒子设置一个高度: 1.2 Clear:both; 1.3 Overflow:hidden; 1.4 使用伪元素 .clearfix:befo ...
- solr学习之域的管理与中文分析器配置
该文使用 Centos6.5 64 位 solr4.10.3 IK-Analyzer中文分析器 一.solr域 在solr中域的概念与lucene中域的概念相同,数据库的一条记录或者一个文 ...
- three.js学习:初学three.js,从立方体开始
目前three.js是浏览器展现3D效果的一个很强大的js工具,遗憾的是没有特别系统而全面的文档(threejs官方文档感觉有些缺漏,可以和WebGL中文网的threejs教程对比着看).好了,根据W ...
- vue搭配axios踩坑
客户端项目中有一个小需求“我的卡券”,有单独入口,所以综合考虑之后,采用了vue来实现,因为是初次使用,导致了选型不当,先用了SUI-Mobile来搭建页面,当决定使用vue的时候,页面也搭建完毕了, ...
- ES6入门箭头函数
箭头函数: 箭头函数可以与变量结构相结合(箭头函数返回对象的时候必须要在对象外边加()) 注意: 1️⃣函数体内的this是定义时所在的对象,而不是使用时的对象 2️⃣不可以当成构造函数,不可用new ...
- 项目经验分享[转自min.jiang]
最近三个月,我非常荣幸的做为TeamLeader带领几个小组成员做了一个国外项目,这里想为大家分享一些小经验,尽管我佣有六年多的项目经验,但我一直的方向是架构师.大家知道架构师一般情况是偏向技 ...
- val和var和Java
object Hello { def main(args :Array[String]) { val k = i } } jvm代码 public final class Hello$ { publi ...
- 实用的DDos攻击工具
来源: http://www.safecdn.cn/linux/2018/12/ddos/95.html 特别提示:仅用于攻防演练及教学测试用途,禁止非法使用 Hyenae 是在windows平台 ...