哈斯克尔:单词,单词分隔符 [英] Haskell : words, unwords delimiter
本文介绍了哈斯克尔:单词,单词分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
words
和 unwords
提供一个分隔符,以使它类似于分裂并加入python?解决方案
不,但它们真的只是(优化版本) 数据.List.break
和 Data.List.intersperse
。
pythonicSplit :: String - >字符 - > [String]
pythonicSplit_ = []
pythonicSplit sc = let(r,rs)= break(== c)s
in r:pythonicSplit rs c
pythonicJoin :: [String] - >字符 - > String
pythonicJoin ss c = intersperse c ss - 或者:flip intersperse
Is there any way I can provide a delimiter to words
and unwords
in haskell, to make it similar to split and join in python?
解决方案
No, but they're really just (optimized versions of) applications of Data.List.break
and Data.List.intersperse
, respectively.
pythonicSplit :: String -> Char -> [String]
pythonicSplit "" _ = []
pythonicSplit s c = let (r,rs) = break (== c) s
in r : pythonicSplit rs c
pythonicJoin :: [String] -> Char -> String
pythonicJoin ss c = intersperse c ss -- or: flip intersperse
这篇关于哈斯克尔:单词,单词分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文