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 ...
随机推荐
- Java基础知识_毕向东_Java基础视频教程笔记(13 字符)
13天-01-String String类适用于描述字符串事物. 常见的操作:1.获取: 1.1字符串中包含的字符数,也就是字符串的长度. int length():获取长度 1.2根据索引值获取位置 ...
- GAC 注册查看与删除
1.复制以下命令粘贴到以管理员权限运行的命令行程序里,回车运行(前提条件得有gacutil.exe注册工具): cd "C:\NETFX 4.0 Tools" 以windows7 ...
- 2018北美部分CS项目学费
yearly cost from official website USC 城里 24credit about 49k + cost of room&food BU 城里 NEU 65k 城里 ...
- idea vs
F8对应vs的F10F7对应vs的F11F9对应vs的F5 ctrl+.对应vs的alt+回车 shift+alt+s 查找文本的出现位置就用Ctrl+F/Ctrl+Shift+F在当前窗口或 ...
- jmx - first demo
1. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...
- CSS的4种定位方式比较
CSS有四种定位(Positioning)方法:Static,Relative, Absolute和Fixed 元素flow, overlap 相对参照物: 能否用offset( top, left, ...
- 《Linux 性能及调优指南》3.1 确认瓶颈
翻译:飞哥 ( http://hi.baidu.com/imlidapeng ) 版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明. 原文名称:<Linux Performance ...
- 三、html样式、链接、表格
- Eureka 客户端启动报错误 Cannot determine embedded database driver class for database type NONE
用这种数据库配置就是死活连不上数据库 提示:Cannot determine embedded database driver class for database type NONE 解决方式: 启 ...
- jq 上传下载进度条
里面只演示了下载的,挂载的是我的七牛服务器上的内容,上传事件和下载是一模一样的,为了大家不乱上传东西到我的服务器,而且我的服务器容量也不大,这里只展示了下载.代码: <!DOCTYPE html ...