aboutsummaryrefslogtreecommitdiffstats
path: root/lib/concepts/Tuple.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-10-31 03:15:28 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-10-31 03:15:28 -0300
commit55174a28581c33c4b6d91066086a2ee7b5c663ea (patch)
treefedb78bf66dd114eedc358ca385cf5f01a65ae0e /lib/concepts/Tuple.ml
parenta8cd08bfe473f01f245a4808e63809ed1cddc0e7 (diff)
downloadRNT-55174a28581c33c4b6d91066086a2ee7b5c663ea.tar.gz
RNT-55174a28581c33c4b6d91066086a2ee7b5c663ea.zip
bencode helpers between dicts and string maps
Diffstat (limited to 'lib/concepts/Tuple.ml')
-rw-r--r--lib/concepts/Tuple.ml14
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/concepts/Tuple.ml b/lib/concepts/Tuple.ml
index dfb7cbe..943c1f6 100644
--- a/lib/concepts/Tuple.ml
+++ b/lib/concepts/Tuple.ml
@@ -23,19 +23,15 @@ and Body : Encoding.Record.BODY = struct
let fields {type_; attributes} =
[ "type", Encoding.Bencode.String type_;
- ( "attributes",
- Encoding.Bencode.Dict
- ( BatMap.String.enum attributes
- |> BatEnum.fold (fun acc (name, value) -> (name, bencode_of_value value) :: acc) [] ) ) ]
+ "attributes", Encoding.Bencode.of_map bencode_of_value attributes ]
let of_fields data =
let open Utilities.Result in
let* type_ = Encoding.Bencode.field "type" data |>> Encoding.Bencode.as_string in
- let* kvs = Encoding.Bencode.field "attributes" data |>> Encoding.Bencode.as_dict in
- kvs
- |> List.map (fun (name, v) -> value_of_bencode v |> Result.map (fun v -> name, v))
- |> Utilities.List.sequence
- |> Result.map (fun kvs -> {type_; attributes= BatMap.String.of_list kvs})
+ let* attributes =
+ Encoding.Bencode.field "attributes" data |>> Encoding.Bencode.to_map value_of_bencode
+ in
+ Ok {type_; attributes}
end
let hash tuple = Representation.to_blob tuple |> Hash.hash_of_blob