aboutsummaryrefslogtreecommitdiffstats
path: root/src/operations.erl
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2025-11-11 00:00:43 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2025-11-11 00:00:43 -0300
commit3063608df6ff1668f683d9d22c57fea29d728d0d (patch)
tree36be7f6c6d901c5984c045d4ce823bd24c37e9af /src/operations.erl
parentb5dbdaa989a86477669aac0bf342029e1d2b6028 (diff)
downloadSakura-3063608df6ff1668f683d9d22c57fea29d728d0d.tar.gz
Sakura-3063608df6ff1668f683d9d22c57fea29d728d0d.zip
migrating to erlang to attach to mnesia
Diffstat (limited to '')
-rw-r--r--src/operations.erl15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/operations.erl b/src/operations.erl
new file mode 100644
index 0000000..7846caf
--- /dev/null
+++ b/src/operations.erl
@@ -0,0 +1,15 @@
+-module(operations).
+-export([select/2, project/2, cartesian_product/2]).
+
+%% @doc Selection - filter tuples based on a predicate
+%% `Predicate` is a function that takes a tuple and returns true/false
+select(Relation, Predicate) ->
+ sets:filter(Predicate, Relation).
+
+%% @doc Projection - select specific attributes from a relation
+%% Note that `AttributeNames` can have duplicate keys, which are ignored
+project(Relation, AttributeNames) when is_list(AttributeNames) ->
+ sets:map(fun (Tuple) -> maps:with(AttributeNames, Tuple) end, Relation).
+
+cartesian_product(Relation1, Relation2) ->
+ sets:from_list([maps:merge(Tuple1, Tuple2) || Tuple1 <- sets:to_list(Relation1), Tuple2 <- sets:to_list(Relation2)], [{version, 2}]).