Skip to content

Commit

Permalink
Add is_set builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj-luminal committed Nov 16, 2019
1 parent 9359917 commit 27e363c
Show file tree
Hide file tree
Showing 2 changed files with 13 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 @@ -222,6 +222,7 @@ defaultBuiltins = HMS.fromList
, (NamedFunction (BuiltinName "is_array"), builtin_is_array)
, (NamedFunction (BuiltinName "is_boolean"), builtin_is_boolean)
, (NamedFunction (BuiltinName "is_object"), builtin_is_object)
, (NamedFunction (BuiltinName "is_set"), builtin_is_set)
, (NamedFunction (BuiltinName "is_string"), builtin_is_string)
, (NamedFunction (QualifiedName "json" "unmarshal"), builtin_json_unmarshal)
, (NamedFunction (BuiltinName "lower"), builtin_lower)
Expand Down Expand Up @@ -333,6 +334,12 @@ builtin_is_object = Builtin (In Out) $ pure $
ObjectV _ -> return True
_ -> return False

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

builtin_is_string :: Monad m => Builtin m
builtin_is_string = Builtin (In Out) $ pure $
\(Cons val Nil) -> case val of
Expand Down
6 changes: 6 additions & 0 deletions tests/rego/builtins-06.rego
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ test_is_boolean {
not is_boolean(1)
not is_boolean([true])
}

test_is_set {
is_set(set())
is_set({set()})
not is_set([set()])
}

0 comments on commit 27e363c

Please sign in to comment.