Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
0adc6fad
Commit
0adc6fad
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Plain Diff
Merge pull request #1464 from metabase/cond-as->-macro
Need cond-as-> macro
parents
0a1c07bf
8c0c7e4f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.dir-locals.el
+1
-0
1 addition, 0 deletions
.dir-locals.el
src/metabase/util.clj
+20
-0
20 additions, 0 deletions
src/metabase/util.clj
test/metabase/test_util.clj
+21
-0
21 additions, 0 deletions
test/metabase/test_util.clj
with
42 additions
and
0 deletions
.dir-locals.el
+
1
−
0
View file @
0adc6fad
...
...
@@ -18,6 +18,7 @@
(
catch-api-exceptions
0
)
(
check
1
)
(
checkp
1
)
(
cond-as->
2
)
(
cond-let
0
)
(
conda
0
)
(
context
2
)
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util.clj
+
20
−
0
View file @
0adc6fad
...
...
@@ -293,4 +293,24 @@
(
throw
(
Exception.
(
format
"Timed out after %d milliseconds."
~
timeout-ms
))))
result
#
))
(
defmacro
cond-as->
"Anaphoric version of `cond->`. Binds EXPR to NAME through a series
of pairs of TEST and FORM. NAME is successively bound to the value
of each FORM whose TEST succeeds.
(defn maybe-wrap-fn [before after f]
(as-> f <>
(fn? before) (fn [] (before) (<>))
(fn? after) (fn [] (try (<>)
(finally (after))))))"
{
:arglists
'
([
expr
nm
tst
form
&
more
])}
[
expr
nm
&
clauses
]
{
:pre
[(
even?
(
count
clauses
))]}
`
(
let
[
~
nm
~
expr
~@
(
apply
concat
(
for
[[
tst
form
]
(
partition
2
clauses
)]
[
nm
`
(
if
~
tst
~
form
~
nm
)]))]
~
nm
))
(
require-dox-in-this-namespace
)
This diff is collapsed.
Click to expand it.
test/metabase/test_util.clj
+
21
−
0
View file @
0adc6fad
...
...
@@ -81,3 +81,24 @@
(
expect
-7
((
rpartial
-
5
10
)
8
))
;;; ## cond-as->
(
expect
100
(
cond-as->
100
<>
))
(
expect
106
(
cond-as->
100
<>
true
(
+
1
<>
)
false
(
+
10
<>
)
:ok
(
+
5
<>
)))
(
expect
101
(
cond-as->
100
<>
(
odd?
<>
)
(
inc
<>
)
(
even?
<>
)
(
inc
<>
)))
(
expect
102
(
cond-as->
100
<>
(
even?
<>
)
(
inc
<>
)
(
odd?
<>
)
(
inc
<>
)))
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