Haskell语言学习笔记(50)Extra
Extra
安装 extra 模块。
$ cabal install extra
Installed extra-1.6
Prelude> :m +Extra
Prelude Extra>
Data.List.Extra String operations
Prelude Extra> lower "This is A TEST"
"this is a test"
Prelude Extra> upper "This is A TEST"
"THIS IS A TEST"
Prelude Extra> trim " hello "
"hello"
Prelude Extra> dropEnd 3 "hello"
"he"
Prelude Extra> takeEnd 3 "hello"
"llo"
Prelude Extra> splitAtEnd 3 "hello"
("he","llo")
Prelude Extra Data.Char> spanEnd isUpper "youRE"
("you","RE")
Prelude Extra Data.Char> spanEnd isUpper "youRE"
("you","RE")
Prelude Extra Data.Char> dropWhileEnd isSpace "foo\n"
"foo"
Prelude Extra> takeWhileEnd even [2,3,4,6]
[4,6]
Prelude Extra> stripSuffix "bar" "foobar"
Just "foo"
Prelude Extra> breakOn "::" "a::b::c"
("a","::b::c")
Prelude Extra> breakOnEnd "::" "a::b::c"
("a::b::","c")
Prelude Extra> splitOn "aaa" "aaaXaaaXaaaXaaa"
["","X","X","X",""]
Prelude Extra> split (== 'a') "aabbaca"
["","","bb","c",""]
Prelude Extra> chunksOf 3 "my test"
["my ","tes","t"]
Data.List.Extra List Basics
Prelude Extra> unsnoc [1,2,3]
Just ([1,2],3)
Prelude Extra> drop1 "abc"
"bc"
Prelude Extra> mconcatMap Data.Monoid.Sum [1,2,3]
Sum {getSum = 6}
Data.List.Extra List operations
Prelude Extra> groupSort [(1,'t'),(3,'t'),(2,'e'),(2,'s')]
[(1,"t"),(2,"es"),(3,"t")]
Prelude Extra> groupSortOn length ["test","of","sized","item"]
[["of"],["test","item"],["sized"]]
Prelude Extra Data.Function> groupSortBy (compare `on` length) ["test","of","sized","item"]
[["of"],["test","item"],["sized"]]
Prelude Extra> nubOrd "this is a test"
"this ae"
Prelude Extra Data.Function> nubOrdBy (compare `on` length) ["a","test","of","this"]
["a","test","of"]
Prelude Extra> nubOrdOn length ["a","test","of","this"]
["a","test","of"]
Prelude Extra> nubOn length ["a","test","of","this"]
["a","test","of"]
Prelude Extra> groupOn length ["test","item","of","sized"]
[["test","item"],["of"],["sized"]]
Prelude Extra> disjoint [1,2,3] [4,5]
True
Prelude Extra> disjoint [1,2,3] [4,1]
False
Prelude Extra> allSame [1,1,2]
False
Prelude Extra> allSame [1,1,1]
True
Prelude Extra> anySame [1,1,2]
True
Prelude Extra> anySame [1,2,3]
False
Prelude Extra> repeatedly (splitAt 3) "my test"
["my ","tes","t"]
Prelude Extra> for [1,2,3] (+1)
[2,3,4]
Prelude Extra> firstJust id [Nothing,Just 3]
Just 3
Prelude Extra> concatUnzip [("a","AB"),("bc","C")]
("abc","ABC")
Prelude Extra> concatUnzip3 [("a","AB",""),("bc","C","123")]
("abc","ABC","123")
Prelude Extra> zipFrom 1 "abc"
[(1,'a'),(2,'b'),(3,'c')]
Prelude Extra> zipWithFrom (+) 1 [3,4,5]
[4,6,8]
Prelude Extra> replace "el" "_" "Hello Bella"
"H_lo B_la"
Haskell语言学习笔记(50)Extra的更多相关文章
- 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语言学习笔记(72)Free Monad
安装 free 包 $ cabal install free Installed free-5.0.2 Free Monad data Free f a = Pure a | Free (f (Fre ...
- Haskell语言学习笔记(49)ByteString Text
Data.ByteString String 是 [Char] 的同义词,在使用上存在List的惰性所带来的性能问题. 在处理大型二进制文件时,可以使用 ByteString 来代替 String. ...
- 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 ...
随机推荐
- mysql 官方docker镜像使用教程
首先是pull image,这里我拉取的是5.x版本最新版: docker pull mysql:5 拉下来以后大可以按照官方的说明无脑启动,但是外部无法访问,所以绑定端口:docker run -- ...
- DataSet和DataTable有用的方法
每一个DataSet都是一个或多个DataTable 对象的集合(DataTable相当于数据库中的表),这些对象由数据行(DataRow).数据列(DataColumn).字段名(Column Na ...
- 读书笔记:Sheldon.M.Ross:概率论基础教程:2014.01.22
贝叶斯公式与全概率公式 全概率公式:如果一件事情的发生有多个可能途径,那么这件事情的发生概率就是在不同途径下此事件发生的条件概率的加权平均.权值为各途径本身的发生概率. 贝叶斯公式:通过例子说明其含义 ...
- css transition transform animation例子讲解
1.transition属性: transition属性是一个速记属性有四个属性:transition-property , transition-duration, transition-timin ...
- 跨域获取json数据
原文地址:http://my.oschina.net/LinBandit/blog/34570 前阵子做了一个前端动态加载json数据的应用,其中使用xmlhttprequest动态加载js,但是 ...
- mongo获取lbs数据
进入mongo目录执行./mongo 命令 #切换数据库use coachloc db.runCommand({geoNear : "coachloc" ,near : [113. ...
- [UE4]封装、继承、多态
面向对象编程的三大特征 一.封装 公开能做什么,隐藏如何做.封装的目的是减少类之间的依赖. 二.继承 让一个类拥有另一个类的状态和行为,前者可以不加修改地完全复用后者的实现,也可以对有些行为做出自己的 ...
- 如何在FreePBX ISO 中文版本安装讯时网关,潮流16FXS 网关和潮流话机
如何在FreePBX ISO 中文版本安装讯时网关,潮流16FXS 网关和潮流话机摘自:http://www.siplab.cn/?p=664 1)迅时的fxo口网关要注册到asterisk,所以现在 ...
- 触屏设备上的多点触碰检测C++代码实现
转自:http://aigo.iteye.com/blog/2272698 代码还是参考自Epic官方的塔防项目:StrategyGame 看了下C++的API,现成的API中貌似只支持单点触碰检测, ...
- python中os常用方法
python中OS常用方法 Python的标准库中的os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问 ...