-module(gleam@set). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new/0, size/1, contains/2, delete/2, to_list/1, fold/3, filter/2, drop/2, take/2, intersection/2, difference/2, insert/2, from_list/1, union/2]). -export_type([set/1]). -opaque set(EXZ) :: {set, gleam@dict:dict(EXZ, list(nil))}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 39). -spec new() -> set(any()). new() -> {set, gleam@dict:new()}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 57). -spec size(set(any())) -> integer(). size(Set) -> maps:size(erlang:element(2, Set)). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 99). -spec contains(set(EYI), EYI) -> boolean(). contains(Set, Member) -> _pipe = erlang:element(2, Set), _pipe@1 = gleam@dict:get(_pipe, Member), gleam@result:is_ok(_pipe@1). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 120). -spec delete(set(EYK), EYK) -> set(EYK). delete(Set, Member) -> {set, gleam@dict:delete(erlang:element(2, Set), Member)}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 138). -spec to_list(set(EYN)) -> list(EYN). to_list(Set) -> gleam@dict:keys(erlang:element(2, Set)). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 178). -spec fold(set(EYT), EYV, fun((EYV, EYT) -> EYV)) -> EYV. fold(Set, Initial, Reducer) -> gleam@dict:fold( erlang:element(2, Set), Initial, fun(A, K, _) -> Reducer(A, K) end ). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 201). -spec filter(set(EYW), fun((EYW) -> boolean())) -> set(EYW). filter(Set, Predicate) -> {set, gleam@dict:filter(erlang:element(2, Set), fun(M, _) -> Predicate(M) end)}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 208). -spec drop(set(EYZ), list(EYZ)) -> set(EYZ). drop(Set, Disallowed) -> gleam@list:fold(Disallowed, Set, fun delete/2). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 226). -spec take(set(EZD), list(EZD)) -> set(EZD). take(Set, Desired) -> {set, gleam@dict:take(erlang:element(2, Set), Desired)}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 230). -spec order(set(EZH), set(EZH)) -> {set(EZH), set(EZH)}. order(First, Second) -> case maps:size(erlang:element(2, First)) > maps:size( erlang:element(2, Second) ) of true -> {First, Second}; false -> {Second, First} end. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 264). -spec intersection(set(EZQ), set(EZQ)) -> set(EZQ). intersection(First, Second) -> {Larger, Smaller} = order(First, Second), take(Larger, to_list(Smaller)). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 282). -spec difference(set(EZU), set(EZU)) -> set(EZU). difference(First, Second) -> drop(First, to_list(Second)). -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 75). -spec insert(set(EYF), EYF) -> set(EYF). insert(Set, Member) -> {set, gleam@dict:insert(erlang:element(2, Set), Member, [])}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 155). -spec from_list(list(EYQ)) -> set(EYQ). from_list(Members) -> Dict = gleam@list:fold( Members, gleam@dict:new(), fun(M, K) -> gleam@dict:insert(M, K, []) end ), {set, Dict}. -file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/set.gleam", 248). -spec union(set(EZM), set(EZM)) -> set(EZM). union(First, Second) -> {Larger, Smaller} = order(First, Second), fold(Smaller, Larger, fun insert/2).