安装 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的更多相关文章

  1. Haskell语言学习笔记(88)语言扩展(1)

    ExistentialQuantification {-# LANGUAGE ExistentialQuantification #-} 存在类型专用的语言扩展 Haskell语言学习笔记(73)Ex ...

  2. Haskell语言学习笔记(79)lambda演算

    lambda演算 根据维基百科,lambda演算(英语:lambda calculus,λ-calculus)是一套从数学逻辑中发展,以变量绑定和替换的规则,来研究函数如何抽象化定义.函数如何被应用以 ...

  3. Haskell语言学习笔记(69)Yesod

    Yesod Yesod 是一个使用 Haskell 语言的 Web 框架. 安装 Yesod 首先更新 Haskell Platform 到最新版 (Yesod 依赖的库非常多,版本不一致的话很容易安 ...

  4. Haskell语言学习笔记(20)IORef, STRef

    IORef 一个在IO monad中使用变量的类型. 函数 参数 功能 newIORef 值 新建带初值的引用 readIORef 引用 读取引用的值 writeIORef 引用和值 设置引用的值 m ...

  5. Haskell语言学习笔记(39)Category

    Category class Category cat where id :: cat a a (.) :: cat b c -> cat a b -> cat a c instance ...

  6. Haskell语言学习笔记(85)Async

    安装 async $ cabal install async async-2.2.1 installed async / wait / concurrently async :: IO a -> ...

  7. Haskell语言学习笔记(72)Free Monad

    安装 free 包 $ cabal install free Installed free-5.0.2 Free Monad data Free f a = Pure a | Free (f (Fre ...

  8. Haskell语言学习笔记(44)Lens(2)

    自定义 Lens 和 Isos -- Some of the examples in this chapter require a few GHC extensions: -- TemplateHas ...

  9. Haskell语言学习笔记(38)Lens(1)

    Lens Lens是一个接近语言级别的库,使用它可以方便的读取,设置,修改一个大的数据结构中某一部分的值. view, over, set Prelude> :m +Control.Lens P ...

随机推荐

  1. Spring事务管理的demo

    事务是逻辑上的一组操作,这组操作要么全部成功,要么全部失败,最为典型的就是银行转账的案例: A要向B转账,现在A,B各自账户中有1000元,A要给B转200元,那么这个转账就必须保证是一个事务,防止中 ...

  2. android adb push 命令

    1.获得root权限:adb root 2.设置/system为可读写:adb remount 3.将PC机上文件复制到手机:adb push 文件名  /system/lib

  3. Anaconda的基本使用

  4. Ubuntu 16.04.3 LTS 部署 Cloud Torrent

    下载安装程序 apt install -y curl sudo curl https://i.jpillora.com/cloud-torrent! | bash 写配置文件 sudo vim /et ...

  5. golang 入门之struct继承,嵌套

    package main import "fmt" type Jocongmin struct{ Name string Home string Want string } fun ...

  6. HDFS的操作SHELL和API

    HDFS的shell操作和JavaAPI的使用: WEB WEB端口50090查看SecondaryNameNode信息.可以查看Hadoop的版本,NameNode的IP,Checkpoint等信息 ...

  7. Elasticsearch分布式机制探究

    Elasticsearch是一套分布式的系统,分布式是为了应对大数据量隐藏了复杂的分布式机制 分片机制 shard = hash(routing) % number_of_primary_shards ...

  8. Android转场动画,Avtivity转场动画;

    转场动画 - 共享元素动画 先看效果: Activity1点击小图标开启Activity2: 开启Activity2效果就像是小图标放大了填充上去的,关闭Activity2回到Activity1时又像 ...

  9. solr系统query检索词特殊字符的处理

    solr是基于 lucence开发的应用,如果query中带有非法字符串,结果很可能是检索出所有内容或者直接报错,所以你对用户的输入必须要先做处理.输入星号,能够检索出所有内容:输入加号,则会报错. ...

  10. luoguP1368 工艺(最小表示法 后缀自动机)

    最小表示法就是直接扫过去 后缀自动机就是每次找最字典序最小儿子输出 最小表示法 /* 最小表示法裸题, 我好像学过来着?? 怎么忘得这么干净 */ #include<cstdio> #in ...