Преглед на файлове

use precise lists of op()

pull/2/head
istr преди 11 години
родител
ревизия
61c8855d27
променени са 1 файла, в които са добавени 20 реда и са изтрити 13 реда
  1. +20
    -13
      src/glc_ops.erl

+ 20
- 13
src/glc_ops.erl Целия файл

@ -19,14 +19,21 @@
union/1 union/1
]). ]).
-type op_lt() :: {atom(), '<', term()}.
-type op_eq() :: {atom(), '=', term()}.
-type op_gt() :: {atom(), '>', term()}.
-type op_exists() :: {atom(), '*'}.
-type op_any() :: {any, [op(), ...]}.
-type op_all() :: {all, [op(), ...]}.
-type op_noop() :: {null, true|false}.
-type op() :: -type op() ::
{atom(), '<', term()} |
{atom(), '=', term()} |
{atom(), '>', term()} |
{atom(), '*'} |
{any, [op(), ...]} |
{all, [op(), ...]} |
{null, true|false}.
op_lt() |
op_eq() |
op_gt() |
op_exists() |
op_any() |
op_all() |
op_noop().
-export_type([op/0]). -export_type([op/0]).
@ -51,7 +58,7 @@ gt(Key, Term) when is_atom(Key) ->
gt(Key, Term) -> gt(Key, Term) ->
erlang:error(badarg, [Key, Term]). erlang:error(badarg, [Key, Term]).
%% @doc Test that a field value is exists.
%% @doc Test that a field value exists.
-spec wc(Key::atom()) -> {Key::atom(), '*'}. -spec wc(Key::atom()) -> {Key::atom(), '*'}.
wc(Key) when is_atom(Key) -> wc(Key) when is_atom(Key) ->
{Key, '*'}; {Key, '*'};
@ -64,7 +71,7 @@ wc(Key) ->
%% in the list must hold for the input event. The list is expected to %% in the list must hold for the input event. The list is expected to
%% be a non-empty list. If the list of filters is an empty list a `badarg' %% be a non-empty list. If the list of filters is an empty list a `badarg'
%% error will be thrown. %% error will be thrown.
-spec all(Conds::nonempty_maybe_improper_list()) -> {all, Conds::nonempty_maybe_improper_list()}.
-spec all(Conds :: [op(), ...]) -> {all, Conds :: [op(), ...]}.
all([_|_]=Conds) -> all([_|_]=Conds) ->
{all, Conds}; {all, Conds};
all(Other) -> all(Other) ->
@ -76,7 +83,7 @@ all(Other) ->
%% in the list must hold for the input event. The list is expected to be %% in the list must hold for the input event. The list is expected to be
%% a non-empty list. If the list of filters is an empty list a `badarg' %% a non-empty list. If the list of filters is an empty list a `badarg'
%% error will be thrown. %% error will be thrown.
-spec any(Conds::nonempty_maybe_improper_list()) -> {any, Conds::nonempty_maybe_improper_list()}.
-spec any(Conds :: [op(), ...]) -> {any, Conds :: [op(), ...]}.
any([_|_]=Conds) -> any([_|_]=Conds) ->
{any, Conds}; {any, Conds};
any(Other) -> any(Other) ->
@ -84,7 +91,7 @@ any(Other) ->
%% @doc Always return `true' or `false'. %% @doc Always return `true' or `false'.
-spec null(Result::boolean()) -> {null, Result::boolean()} | no_return().
-spec null(Result::boolean()) -> {null, Result::boolean()}.
null(Result) when is_boolean(Result) -> null(Result) when is_boolean(Result) ->
{null, Result}; {null, Result};
null(Result) -> null(Result) ->
@ -96,7 +103,7 @@ null(Result) ->
%% to use a finalized query to construct a new query will result %% to use a finalized query to construct a new query will result
%% in a `badarg' error. %% in a `badarg' error.
-spec with(Query::op(), Fun::fun((gre:event()) -> term())) -> -spec with(Query::op(), Fun::fun((gre:event()) -> term())) ->
{with, Query::op(), Fun::fun((gre:event()) -> term())} | no_return().
{with, Query::op(), Fun::fun((gre:event()) -> term())}.
with(Query, Fun) when is_function(Fun, 1) -> with(Query, Fun) when is_function(Fun, 1) ->
{with, Query, Fun}; {with, Query, Fun};
with(Query, Fun) -> with(Query, Fun) ->
@ -112,7 +119,7 @@ with(Query, Fun) ->
%% All queries are expected to be valid and have an output action other %% All queries are expected to be valid and have an output action other
%% than the default which is `output'. If these expectations don't hold %% than the default which is `output'. If these expectations don't hold
%% a `badarg' error will be thrown. %% a `badarg' error will be thrown.
-spec union(Queries::[op()]) -> {union, Queries::[op()]} | no_return().
-spec union(Queries::[op()]) -> {union, Queries::[op()]}.
union(Queries) -> union(Queries) ->
case [Query || Query <- Queries, glc_lib:onoutput(Query) =:= output] of case [Query || Query <- Queries, glc_lib:onoutput(Query) =:= output] of
[] -> {union, Queries}; [] -> {union, Queries};

Зареждане…
Отказ
Запис