MCPcopy Create free account
hub / github.com/effect-app/libs / make_

Function make_

packages/effect-app/src/NonEmptySet.ts:14–68  ·  view source on GitHub ↗
(ord: Order.Order<A>, eq_?: Equivalence.Equivalence<A>)

Source from the content-addressed store, hash-verified

12export type NonEmptySet<A> = Set<A> & NonEmptyBrand
13
14function make_<A>(ord: Order.Order<A>, eq_?: Equivalence.Equivalence<A>) {
15 const eq = eq_
16 ?? ((x, y) => ord(x, y) === 0)
17
18 const fromArray_ = fromArrayOriginal(eq)
19 const fromArray = flow(fromArray_, fromSet)
20 const fromNonEmptyArray = (arr: NonEmptyReadonlyArray<A>) => fromArray_(arr) as NonEmptySet<A>
21 const concat_ = (set: NonEmptySet<A>, it: Iterable<A>) => fromArray([...set, ...it])
22 const insert__ = insertOriginal(eq)
23 const insert: (a: A) => (set: NonEmptySet<A>) => NonEmptySet<A> = insert__ as any
24 const insert_: (set: NonEmptySet<A>, a: A) => NonEmptySet<A> = insert_Original as any
25
26 function replace_(set: NonEmptySet<A>, a: A) {
27 return (pipe(filter_(set, (x) => !eq(x, a)), insert__(a)) as NonEmptySet<A>)
28 }
29
30 const toArray__ = toArrayOriginal(ord)
31
32 function toArray(s: NonEmptySet<A>) {
33 return toArray__(s) as NonEmptyReadonlyArray<A>
34 }
35
36 const remove__ = remove(eq)
37 const filterMap__ = filterMap(eq)
38
39 return {
40 insert,
41 insert_,
42 remove: (a: A) => flow(remove__(a), fromSet),
43 remove_: flow(remove_(eq), fromSet),
44 reduce: reduce(ord),
45 reduce_: reduce_(ord),
46 replace: (a: A) => (set: NonEmptySet<A>) => replace_(set, a),
47 replace_,
48 toArray,
49 fromArray,
50 fromNonEmptyArray,
51 from: (it: Iterable<A>) => fromArray([...it]),
52 of: (a: A) => new Set<A>([a]) as unknown as NonEmptySet<A>,
53 concat_,
54 concat: (it: Iterable<A>) => (set: NonEmptySet<A>) => concat_(set, it),
55
56 // A and B the same, useful when editing elements.
57 map: map(eq) as unknown as <A>(
58 f: (x: A) => A
59 ) => (set: NonEmptySet<A>) => NonEmptySet<A>,
60 map_: map_(eq) as unknown as <A>(
61 set: NonEmptySet<A>,
62 f: (x: A) => A
63 ) => NonEmptySet<A>,
64 filterMap: (f: (a: A) => Option.Option<A>) => flow(filterMap__<A>((a) => f(a)), fromSet),
65 filterMap_: flow(filterMap_(eq), fromSet)
66 }
67 // TODO: extend
68}
69
70class Wrapper<A> {
71 wrapped(ord: Order.Order<A>, eq?: Equivalence.Equivalence<A>) {

Callers 1

wrappedMethod · 0.70

Calls 12

removeFunction · 0.90
filterMapFunction · 0.90
remove_Function · 0.90
reduceFunction · 0.90
reduce_Function · 0.90
fromArrayFunction · 0.90
mapFunction · 0.90
map_Function · 0.90
filterMap_Function · 0.90
replace_Function · 0.70
concat_Function · 0.70
fFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…