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 ...
随机推荐
- Joyoi公路乘车(原tyvj1015)
题目:http://www.joyoi.cn/problem/tyvj-1015 水题.连优化都不用. #include<iostream> #include<cstdio> ...
- Navicat导出opencart2.3数据字典
步骤请参考:http://blog.csdn.net/maquealone/article/details/60764420 运行SQL: 备注:opcml是数据库名称. select TABLE ...
- bzoj1193 马步距离
Description 求点(xs,ys)走马步到(xp,yp)的最小步数 Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Out ...
- java web程序 上机考试登陆界面设计实现
今天是java web上机.做一个登陆注册的界面.要求:jsp.mysql数据库,js做一个美观的界面.功能.可以添加 更多啊.我做的界面被老师狠狠的扣了分.问题在于.当用户没有输入任何信息(没有输入 ...
- onload属性使用方法
onload事件属性是页面的图片文字等全部加载完毕后执行的事件 window.onload=fun1;function fun1(){ document.getElementsByTagName ...
- unity3d中给GameObject绑定脚本的代码
一.获取GameObject 1.GameObject.Find() 通过场景里面的名子或者一个路径直接获取游戏对象. GameObject root = GameObject.Find(“Ga ...
- php笔记篇(二)
mysql中key .primary key .unique key 与index区别(http://www.manongjc.com/article/1487.html) php is_file() ...
- Spring AOP的总结
- Executor框架(二)Executor 与 ExecutorService两个基本接口
一.Executor 接口简介 Executor接口是Executor框架的一个最基本的接口,Executor框架的大部分类都直接或间接地实现了此接口. 只有一个方法 void execute(Run ...
- web安全深度剖析 pdf
扫加公众号,回复“web安全深度剖析",免费获取此书.