1313//// > [`dict.from_ascending_list`](#from_ascending_list).
1414
1515use aiken/ builtin
16+ use aiken/ collection/ dict/ union.{UnionStrategy }
1617
1718/// An opaque `Dict`. The type is opaque because the module maintains some
1819/// invariant, namely: there's only one occurrence of a given key in the dictionary.
@@ -755,16 +756,14 @@ pub fn insert_with_alt(
755756 self: Dict < key, value> ,
756757 key k: ByteArray ,
757758 value v: value,
758- with: fn (ByteArray , value, value) ->
759- fn (fn (value) -> Pairs < ByteArray , value> , fn () -> Pairs < ByteArray , value> ) ->
760- Pairs < ByteArray , value> ,
759+ with: UnionStrategy < ByteArray , value> ,
761760) -> Dict < key, value> {
762761 Dict {
763762 inner: do_insert_with_alt (
764763 self.inner,
765764 k,
766765 v,
767- fn (k, v1, v2) { with (k, v2, v1) },
766+ fn (k, v1, v2, some, none ) { with (k, v2, v1, some, none ) },
768767 ),
769768 }
770769}
@@ -783,13 +782,10 @@ test insert_with_1() {
783782}
784783
785784test insert_with_alt_1 () {
786- let sum =
787- fn (_k, a, b) { fn (som, _non) { som (a + b) } }
788-
789785 let result =
790786 empty
791- |> insert_with_alt (key: "foo" , value: 1 , with: sum)
792- |> insert_with_alt (key: "bar" , value: 2 , with: sum)
787+ |> insert_with_alt (key: "foo" , value: 1 , with: union. sum)
788+ |> insert_with_alt (key: "bar" , value: 2 , with: union. sum)
793789 |> to_pairs ()
794790
795791 result == [Pair ("bar" , 2 ), Pair ("foo" , 1 )]
@@ -1050,9 +1046,7 @@ pub fn union_with(
10501046pub fn union_with_alt (
10511047 left: Dict < key, value> ,
10521048 right: Dict < key, value> ,
1053- with: fn (ByteArray , value, value) ->
1054- fn (fn (value) -> Pairs < ByteArray , value> , fn () -> Pairs < ByteArray , value> ) ->
1055- Pairs < ByteArray , value> ,
1049+ with: UnionStrategy < ByteArray , value> ,
10561050) -> Dict < key, value> {
10571051 Dict { inner: do_union_with_alt (left.inner, right.inner, with) }
10581052}
@@ -1072,9 +1066,7 @@ fn do_union_with(
10721066fn do_union_with_alt (
10731067 left: Pairs < ByteArray , value> ,
10741068 right: Pairs < ByteArray , value> ,
1075- with: fn (ByteArray , value, value) ->
1076- fn (fn (value) -> Pairs < ByteArray , value> , fn () -> Pairs < ByteArray , value> ) ->
1077- Pairs < ByteArray , value> ,
1069+ with: UnionStrategy < ByteArray , value> ,
10781070) -> Pairs < ByteArray , value> {
10791071 when left is {
10801072 [] -> right
@@ -1111,9 +1103,7 @@ fn do_insert_with_alt(
11111103 self: Pairs < ByteArray , value> ,
11121104 key k: ByteArray ,
11131105 value v: value,
1114- with: fn (ByteArray , value, value) ->
1115- fn (fn (value) -> Pairs < ByteArray , value> , fn () -> Pairs < ByteArray , value> ) ->
1116- Pairs < ByteArray , value> ,
1106+ with: UnionStrategy < ByteArray , value> ,
11171107) -> Pairs < ByteArray , value> {
11181108 when self is {
11191109 [] -> [Pair (k, v)]
@@ -1122,7 +1112,10 @@ fn do_insert_with_alt(
11221112 [Pair (k, v), .. self]
11231113 } else {
11241114 if k == k2 {
1125- with (k, v, v2)(
1115+ with (
1116+ k,
1117+ v,
1118+ v2,
11261119 fn (combined) { [Pair (k, combined), .. rest] },
11271120 fn () { rest },
11281121 )
0 commit comments