Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
itminedu
snf-ganeti
Commits
5aa48dbe
Commit
5aa48dbe
authored
15 years ago
by
Iustin Pop
Browse files
Options
Downloads
Patches
Plain Diff
Generalize some Result function into monad ones
We don't really needed, but is more clean like this.
parent
942403e6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Ganeti/HTools/Rapi.hs
+3
-3
3 additions, 3 deletions
Ganeti/HTools/Rapi.hs
Ganeti/HTools/Utils.hs
+19
-19
19 additions, 19 deletions
Ganeti/HTools/Utils.hs
with
22 additions
and
22 deletions
Ganeti/HTools/Rapi.hs
+
3
−
3
View file @
5aa48dbe
...
...
@@ -73,9 +73,9 @@ parseInstance a =
(
show
`
liftM
`
disk
)
|+
running
|+
pnode
|+
snode
boolToYN
::
Bool
->
Result
String
boolToYN
True
=
Ok
"Y"
boolToYN
_
=
Ok
"N"
boolToYN
::
(
Monad
m
)
=>
Bool
->
m
String
boolToYN
True
=
return
"Y"
boolToYN
_
=
return
"N"
parseNode
::
JSObject
JSValue
->
Result
String
parseNode
a
=
...
...
This diff is collapsed.
Click to expand it.
Ganeti/HTools/Utils.hs
+
19
−
19
View file @
5aa48dbe
...
...
@@ -57,9 +57,9 @@ instance Monad Result where
return
=
Ok
fail
=
Bad
fromJResult
::
J
.
Result
a
->
Result
a
fromJResult
(
J
.
Error
x
)
=
Bad
x
fromJResult
(
J
.
Ok
x
)
=
Ok
x
fromJResult
::
Monad
m
=>
J
.
Result
a
->
m
a
fromJResult
(
J
.
Error
x
)
=
fail
x
fromJResult
(
J
.
Ok
x
)
=
return
x
-- | Comma-join a string list.
commaJoin
::
[
String
]
->
String
...
...
@@ -111,42 +111,42 @@ readData nd =
exitWith
$
ExitFailure
1
Ok
x
->
return
x
)
readEitherString
::
J
.
JSValue
->
Result
String
readEitherString
::
(
Monad
m
)
=>
J
.
JSValue
->
m
String
readEitherString
v
=
case
v
of
J
.
JSString
s
->
Ok
$
J
.
fromJSString
s
_
->
Bad
"Wrong JSON type"
J
.
JSString
s
->
return
$
J
.
fromJSString
s
_
->
fail
"Wrong JSON type"
loadJSArray
::
String
->
Result
[
J
.
JSObject
J
.
JSValue
]
loadJSArray
::
(
Monad
m
)
=>
String
->
m
[
J
.
JSObject
J
.
JSValue
]
loadJSArray
s
=
fromJResult
$
J
.
decodeStrict
s
fromObj
::
J
.
JSON
a
=>
String
->
J
.
JSObject
J
.
JSValue
->
Result
a
fromObj
::
(
J
.
JSON
a
,
Monad
m
)
=>
String
->
J
.
JSObject
J
.
JSValue
->
m
a
fromObj
k
o
=
case
lookup
k
(
J
.
fromJSObject
o
)
of
Nothing
->
Bad
$
printf
"key '%s' not found"
k
Nothing
->
fail
$
printf
"key '%s' not found"
k
Just
val
->
fromJResult
$
J
.
readJSON
val
getStringElement
::
String
->
J
.
JSObject
J
.
JSValue
->
Result
String
getStringElement
::
(
Monad
m
)
=>
String
->
J
.
JSObject
J
.
JSValue
->
m
String
getStringElement
=
fromObj
getIntElement
::
String
->
J
.
JSObject
J
.
JSValue
->
Result
Int
getIntElement
::
(
Monad
m
)
=>
String
->
J
.
JSObject
J
.
JSValue
->
m
Int
getIntElement
=
fromObj
getBoolElement
::
String
->
J
.
JSObject
J
.
JSValue
->
Result
Bool
getBoolElement
::
(
Monad
m
)
=>
String
->
J
.
JSObject
J
.
JSValue
->
m
Bool
getBoolElement
=
fromObj
getListElement
::
String
->
J
.
JSObject
J
.
JSValue
->
Result
[
J
.
JSValue
]
getListElement
::
(
Monad
m
)
=>
String
->
J
.
JSObject
J
.
JSValue
->
m
[
J
.
JSValue
]
getListElement
=
fromObj
getObjectElement
::
String
->
J
.
JSObject
J
.
JSValue
->
Result
(
J
.
JSObject
J
.
JSValue
)
getObjectElement
::
(
Monad
m
)
=>
String
->
J
.
JSObject
J
.
JSValue
->
m
(
J
.
JSObject
J
.
JSValue
)
getObjectElement
=
fromObj
asJSObject
::
J
.
JSValue
->
Result
(
J
.
JSObject
J
.
JSValue
)
asJSObject
(
J
.
JSObject
a
)
=
Ok
a
asJSObject
_
=
Bad
"not an object"
asJSObject
::
(
Monad
m
)
=>
J
.
JSValue
->
m
(
J
.
JSObject
J
.
JSValue
)
asJSObject
(
J
.
JSObject
a
)
=
return
a
asJSObject
_
=
fail
"not an object"
asObjectList
::
[
J
.
JSValue
]
->
Result
[
J
.
JSObject
J
.
JSValue
]
asObjectList
::
(
Monad
m
)
=>
[
J
.
JSValue
]
->
m
[
J
.
JSObject
J
.
JSValue
]
asObjectList
=
sequence
.
map
asJSObject
-- | Function to concat two strings with a separator under a monad
...
...
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