Skip to content

Commit

Permalink
Add is_boolean builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj authored and jaspervdj-luminal committed Nov 16, 2019
1 parent 1e8b416 commit 9359917
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Fregot/Eval/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ defaultBuiltins = HMS.fromList
, (NamedFunction (BuiltinName "indexof"), builtin_indexof)
, (NamedFunction (BuiltinName "intersection"), builtin_intersection)
, (NamedFunction (BuiltinName "is_array"), builtin_is_array)
, (NamedFunction (BuiltinName "is_boolean"), builtin_is_boolean)
, (NamedFunction (BuiltinName "is_object"), builtin_is_object)
, (NamedFunction (BuiltinName "is_string"), builtin_is_string)
, (NamedFunction (QualifiedName "json" "unmarshal"), builtin_json_unmarshal)
Expand Down Expand Up @@ -320,6 +321,12 @@ builtin_is_array = Builtin (In Out) $ pure $
ArrayV _ -> return True
_ -> return False

builtin_is_boolean :: Monad m => Builtin m
builtin_is_boolean = Builtin (In Out) $ pure $
\(Cons val Nil) -> case val of
BoolV _ -> return True
_ -> return False

builtin_is_object :: Monad m => Builtin m
builtin_is_object = Builtin (In Out) $ pure $
\(Cons val Nil) -> case val of
Expand Down
9 changes: 9 additions & 0 deletions tests/rego/builtins-06.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 'is_' functions
package fregot.tests.builtins_06

test_is_boolean {
is_boolean(true)
is_boolean(false)
not is_boolean(1)
not is_boolean([true])
}

0 comments on commit 9359917

Please sign in to comment.