Shell: add assoc combinator to Data_encoding.

This commit is contained in:
Benjamin Canou 2016-09-09 17:02:43 +02:00
parent f42e9d12ac
commit e80ce1e8d5
3 changed files with 8 additions and 0 deletions

View File

@ -147,6 +147,8 @@ val merge_tups : 'a1 encoding -> 'a2 encoding -> ('a1 * 'a2) encoding
val array : 'a encoding -> 'a array encoding val array : 'a encoding -> 'a array encoding
val list : 'a encoding -> 'a list encoding val list : 'a encoding -> 'a list encoding
val assoc : 'a encoding -> (string * 'a) list encoding
type 't case type 't case
val case : val case :
?tag:int -> 'a encoding -> ('t -> 'a option) -> ('a -> 't) -> 't case ?tag:int -> 'a encoding -> ('t -> 'a option) -> ('a -> 't) -> 't case

View File

@ -719,6 +719,10 @@ module Encoding = struct
`Variable in `Variable in
make @@ Mu (kind, name, self) make @@ Mu (kind, name, self)
let assoc enc =
let json = Json_encoding.assoc (Json.get_json enc) in
let binary = list (tup2 string enc) in
raw_splitted ~json ~binary
end end
include Encoding include Encoding

View File

@ -155,6 +155,8 @@ val merge_tups : 'a1 encoding -> 'a2 encoding -> ('a1 * 'a2) encoding
val array : 'a encoding -> 'a array encoding val array : 'a encoding -> 'a array encoding
val list : 'a encoding -> 'a list encoding val list : 'a encoding -> 'a list encoding
val assoc : 'a encoding -> (string * 'a) list encoding
type 't case type 't case
val case : val case :
?tag:int -> 'a encoding -> ('t -> 'a option) -> ('a -> 't) -> 't case ?tag:int -> 'a encoding -> ('t -> 'a option) -> ('a -> 't) -> 't case