diff options
Diffstat (limited to '')
| -rw-r--r-- | lib/concepts/Tuple.ml | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/concepts/Tuple.ml b/lib/concepts/Tuple.ml index 296bf26..28dadc5 100644 --- a/lib/concepts/Tuple.ml +++ b/lib/concepts/Tuple.ml @@ -1,8 +1,8 @@ -type t = { type_ : string; attributes : Value.value BatMap.String.t } +type t = {type_: string; attributes: Value.value BatMap.String.t} let malformed_value () = - Condition.condition "malformed-tuple-value" - "A tuple field did not conform to what was expected" Condition.empty + Condition.condition "malformed-tuple-value" "A tuple field did not conform to what was expected" + Condition.empty let bencode_of_value = function | Value.String s -> Encoding.Bencode.Tagged ('s', Encoding.Bencode.String s) @@ -13,8 +13,7 @@ let value_of_bencode = function | Encoding.Bencode.Tagged ('i', Encoding.Bencode.Int n) -> Ok (Value.Integer n) | _ -> Error (malformed_value ()) -module rec Representation : (Encoding.Record.S with type t = t) = - Encoding.Record.Make (Body) +module rec Representation : (Encoding.Record.S with type t = t) = Encoding.Record.Make (Body) and Body : Encoding.Record.BODY = struct type nonrec t = t @@ -22,24 +21,21 @@ and Body : Encoding.Record.BODY = struct let tag = 'T' let malformed = malformed_value - let fields { type_; attributes } = + 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.Dict + ( BatMap.String.enum attributes + |> BatEnum.fold (fun acc (name, value) -> (name, bencode_of_value value) :: acc) [] ) ) ] let of_fields data = let open Utilities.Result in let* type_ = Encoding.Bencode.field "type" data |> fmap Encoding.Bencode.as_string in let* kvs = Encoding.Bencode.field "attributes" data |> fmap Encoding.Bencode.as_dict in kvs - |> List.map (fun (name, v) -> value_of_bencode v |> Result.map (fun v -> (name, v))) + |> 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 }) + |> Result.map (fun kvs -> {type_; attributes= BatMap.String.of_list kvs}) end let hash tuple = Representation.to_blob tuple |> Hash.hash_of_blob |
