Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
outillage
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alice Brenon
outillage
Commits
2a451868
Commit
2a451868
authored
1 year ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Cleaning deprecated libs (renamed Filter and then enhanced)
parent
eee52960
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/Text/Editor.bak.hs
+0
-101
0 additions, 101 deletions
lib/Text/Editor.bak.hs
lib/Text/Editor.hs
+0
-47
0 additions, 47 deletions
lib/Text/Editor.hs
with
0 additions
and
148 deletions
lib/Text/Editor.bak.hs
deleted
100644 → 0
+
0
−
101
View file @
eee52960
{-# LANGUAGE FlexibleInstances, NamedFieldPuns, OverloadedStrings #-}
module
Text.Editor
(
-- Editor
--, Filter(..)
Editable
(
..
)
--, (|->)
--, (|=>)
,
(
<>.
)
,
editor
--, pureEditor
,
fileFilter
--, runAll
,
stdinList
)
where
import
Control.Monad.IO.Class
(
MonadIO
(
..
))
import
Data.Text
as
Text
(
Text
,
intercalate
,
lines
,
pack
,
unpack
)
import
Data.Text.IO
as
Text
(
readFile
,
writeFile
)
import
System.FilePath
(
replaceDirectory
,
replaceExtension
)
data
Filter
m
a
b
=
Filter
{
transform
::
a
->
m
b
,
outputFormat
::
Maybe
String
}
type
Editor
m
a
=
Filter
m
a
a
{-
data Editor m a = Editor {
transform :: a -> m a
, outputFormat :: Maybe String
}
-}
{-
editor :: (a -> m a) -> Editor m a
editor f = Filter { transform = f, outputFormat = Nothing }
--editor f = Editor { transform = f, outputFormat = Nothing }
pureEditor :: Applicative m => (a -> a) -> Editor m a
pureEditor = editor . (pure .)
-}
class
Editable
a
where
enter
::
Text
->
a
leave
::
a
->
Text
instance
Editable
[
Text
]
where
enter
=
Text
.
lines
leave
=
Text
.
intercalate
"
\n
"
instance
Editable
String
where
enter
=
Text
.
unpack
leave
=
Text
.
pack
type
EditionProcess
m
=
FilePath
->
FilePath
->
m
()
fileFilter
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
FilePath
->
FilePath
)
->
(
a
->
m
b
)
->
EditionProcess
m
fileFilter
fixFormat
transform
target
input
=
--(|->) (Editor {transform, outputFormat}) target input =
liftIO
(
Text
.
readFile
input
)
>>=
transform
.
enter
>>=
liftIO
.
Text
.
writeFile
output
.
leave
where
output
=
fixFormat
$
replaceDirectory
input
target
(
<>.
)
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
a
->
m
b
)
->
String
->
EditionProcess
m
(
<>.
)
transform
extension
=
fileFilter
(`
replaceExtension
`
extension
)
transform
editor
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
a
->
m
b
)
->
EditionProcess
m
editor
=
fileFilter
id
{-
run :: (Editable a, Editable b, MonadIO m) => Filter m a b -> FilePath -> FilePath -> m ()
run = (|->)
(|->) :: (Editable a, Editable b, MonadIO m) => Filter m a b -> FilePath -> FilePath -> m ()
--(|->) :: (Editable a, MonadIO m) => Editor m a -> FilePath -> FilePath -> m ()
(|->) (Filter {transform, outputFormat}) target input =
--(|->) (Editor {transform, outputFormat}) target input =
liftIO (Text.readFile input)
>>= transform . enter
>>= liftIO . Text.writeFile output . leave
where
fixFormat = maybe id (flip replaceExtension) outputFormat
output = fixFormat $ replaceDirectory input target
runAll :: (Editable a, Foldable t, MonadIO m) => Editor m a -> FilePath -> t FilePath -> m ()
runAll = (|=>)
-- (|=>) :: (Editable a, MonadIO m) => Editor m a -> FilePath -> String -> m ()
(|=>) :: (Editable a, Foldable t, MonadIO m) => Editor m a -> FilePath -> t FilePath -> m ()
--editor |=> target = mapM_ (editor |-> target) . Prelude.lines
editor |=> target = mapM_ (editor |-> target)
-}
stdinList
::
MonadIO
m
=>
m
[
FilePath
]
stdinList
=
Prelude
.
lines
<$>
liftIO
getContents
This diff is collapsed.
Click to expand it.
lib/Text/Editor.hs
deleted
100644 → 0
+
0
−
47
View file @
eee52960
{-# LANGUAGE FlexibleInstances, NamedFieldPuns, OverloadedStrings #-}
module
Text.Editor
(
Editable
(
..
)
,
(
<>.
)
,
apply
,
fileFilter
,
xargs
)
where
import
Control.Monad.IO.Class
(
MonadIO
(
..
))
import
Data.ByteString.Lazy
as
BS
(
ByteString
,
pack
,
unpack
)
import
Data.Text
as
Text
(
Text
,
intercalate
,
lines
,
pack
,
unpack
)
import
Data.Text.IO
as
Text
(
readFile
,
writeFile
)
import
System.FilePath
(
replaceDirectory
,
replaceExtension
)
class
Editable
a
where
enter
::
Text
->
a
leave
::
a
->
Text
instance
Editable
[
Text
]
where
enter
=
Text
.
lines
leave
=
Text
.
intercalate
"
\n
"
instance
Editable
String
where
enter
=
Text
.
unpack
leave
=
Text
.
pack
type
Editor
m
=
FilePath
->
FilePath
->
m
()
fileFilter
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
FilePath
->
FilePath
)
->
(
a
->
m
b
)
->
Editor
m
fileFilter
fixFormat
transform
target
input
=
liftIO
(
Text
.
readFile
input
)
>>=
transform
.
enter
>>=
liftIO
.
Text
.
writeFile
output
.
leave
where
output
=
fixFormat
$
replaceDirectory
input
target
(
<>.
)
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
a
->
m
b
)
->
String
->
Editor
m
(
<>.
)
transform
extension
=
fileFilter
(`
replaceExtension
`
extension
)
transform
apply
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
a
->
m
b
)
->
Editor
m
apply
=
fileFilter
id
xargs
::
(
Editable
a
,
Editable
b
,
MonadIO
m
)
=>
(
a
->
m
b
)
->
FilePath
->
m
()
xargs
transform
target
=
Prelude
.
lines
<$>
liftIO
getContents
>>=
mapM_
(
apply
transform
target
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment