diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-06-26 12:15:27 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-06-26 12:15:55 -0400 |
commit | 63f9aba33b45e5bab688ffaa5e4182801c152828 (patch) | |
tree | 1f4e16640503b27bbd0f33241cbe1cb2c4a4eb89 /Utility/Split.hs | |
parent | c799b05deae723690bfac5e867f7985e8f800d0d (diff) | |
download | git-repair-63f9aba33b45e5bab688ffaa5e4182801c152828.tar.gz |
merge from git-annex
Removes dependency on MissingH, adding a dependency on split instead.
This commit was sponsored by Brock Spratlen on Patreon.
Diffstat (limited to 'Utility/Split.hs')
-rw-r--r-- | Utility/Split.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Utility/Split.hs b/Utility/Split.hs new file mode 100644 index 0000000..decfe7d --- /dev/null +++ b/Utility/Split.hs @@ -0,0 +1,30 @@ +{- split utility functions + - + - Copyright 2017 Joey Hess <id@joeyh.name> + - + - License: BSD-2-clause + -} + +{-# OPTIONS_GHC -fno-warn-tabs #-} + +module Utility.Split where + +import Data.List (intercalate) +import Data.List.Split (splitOn) + +-- | same as Data.List.Utils.split +-- +-- intercalate x . splitOn x === id +split :: Eq a => [a] -> [a] -> [[a]] +split = splitOn + +-- | Split on a single character. This is over twice as fast as using +-- split on a list of length 1, while producing identical results. -} +splitc :: Eq c => c -> [c] -> [[c]] +splitc c s = case break (== c) s of + (i, _c:rest) -> i : splitc c rest + (i, []) -> i : [] + +-- | same as Data.List.Utils.replace +replace :: Eq a => [a] -> [a] -> [a] -> [a] +replace old new = intercalate new . split old |