text stringlengths 0 601k |
|---|
let real_minus_service2 = minus_service prefix_dir2 |
let rec repeat i json = if i <= 0 then [ ] else json :: repeat ( i - 1 ) json |
let dir = Directory . register1 dir repeat_service ( fun i json -> return ( ` A ( repeat i json ) ) ) |
let dir = Directory . register1 dir add_service ( fun i j -> return ( i + j ) ) |
let dir = Directory . register2 dir alternate_add_service ( fun i j ( ) -> return ( float_of_int i . + j ) ) |
let dir = Directory . register dir alternate_add_service ' ( fun ( i , j ) ( ) -> return ( i + j ) ) |
let dir = Directory . register dir dummy_service ( fun ( ( ( ( ( ( ( ( ) , a ) , b ) , c ) , d ) , e ) , f ) , g ) ( ) -> return ( ) ) |
let prefixed_dir = Directory . register2 prefixed_dir ( minus_service Path . root ) ( fun i j ( ) -> return ( i . - float_of_int j ) ) |
let dir = Directory . register_dynamic_directory1 dir prefix_dir1 ( fun _ -> Lwt . return prefixed_dir ) |
let dir = Directory . register_dynamic_directory1 dir prefix_dir2 ( fun _ -> Lwt . return ( Directory . map ( fun ( ( ) , x ) -> ( ( ) , float_of_int x ) ) prefixed_dir ) ) |
let dir = Directory . register_describe_directory_service dir describe_service |
let request service args arg = let args , arg = forge_request service args arg in match Lwt . state ( Directory . lookup dir ( ) args ) with | Lwt . Return handler -> begin match Lwt . state ( handler arg ) with | Lwt . Return { code = 200 ; body = Single x } -> begin match read_answer service x with | Ok x -> x | Erro... |
let ( ) = let dir = request describe_service ( ) ( Some true ) in Format . printf " [ @< v >% a ] . " @@ Description . pp_print_directory_descr dir |
let ( ) = let test service args arg expected = request service args arg = expected in assert ( test repeat_service ( ( ) , 3 ) ( ` A [ ] ) ( ` A ( repeat 3 ( ` A [ ] ) ) ) ) ; assert ( test add_service ( ( ) , 2 ) 3 5 ) ; assert ( test alternate_add_service ( ( ( ) , 1 ) , 2 . 5 ) ( ) 3 . 5 ) ; assert ( test real_minus... |
let ( ) = Printf . printf " \ n ### OK Resto ###\ n \ n " %! |
module Make2 ( M : Monad_let . S2 ) ( T : sig type t end ) : Monad_let . S with type ' a t = ( ' a , T . t ) M . t = struct type ' a t = ( ' a , T . t ) M . t let map = M . map let bind = M . bind let return = M . return let all = M . all let all_unit = M . all_unit let ignore_m = M . ignore_m let join = M . join modul... |
module Make3 ( M : Monad_let . S3 ) ( T : sig type t1 type t2 end ) : Monad_let . S with type ' a t = ( ' a , T . t1 , T . t2 ) M . t = struct type ' a t = ( ' a , T . t1 , T . t2 ) M . t let map = M . map let bind = M . bind let return = M . return let all = M . all let all_unit = M . all_unit let ignore_m = M . ignor... |
let request_up v = incr v |
let request_down v = decr v |
let is_computing v = ! v <> 0 |
let send ( ? timeout : float option ) request_count ( url : string ) ( meth : Common . meth ) ( ? data : string option ) ( hydrate : string -> ' a ) : ' a Api . result Lwt . t = let reply , feeder = Lwt . task ( ) in let handler status response_text = let result_code : Result_util . status option = match status with | ... |
let kasa_error l = Lwt . return_error ( List . fold_left ( fun acc m -> Exception_without_parameter . add_uncaught_error ( Exception_without_parameter . build_uncaught_exception ~ file_name " : rest_api " ~ message : m . Result_util . text Exit ) acc ) Exception_without_parameter . empty_error_handler l ) ( ~ timeout :... |
type status = Pass | Skip | Fail |
type t = { status : status ; reason : string option } |
let result_of_status s = { status = s ; reason = None } |
let pass = result_of_status Pass |
let skip = result_of_status Skip |
let fail = result_of_status Fail |
let result_with_reason s r = { status = s ; reason = Some r } |
let pass_with_reason r = result_with_reason Pass r |
let skip_with_reason r = result_with_reason Skip r |
let fail_with_reason r = result_with_reason Fail r |
let string_of_status = function | Pass -> " passed " | Skip -> " skipped " | Fail -> " failed " |
let string_of_reason = function | None -> " " | Some reason -> ( " ( " ^ reason ^ " ) " ) |
let string_of_result r = ( string_of_status r . status ) ^ ( string_of_reason r . reason ) |
let is_pass r = r . status = Pass |
let is_skip r = r . status = Skip |
let is_fail r = r . status = Fail |
let suite = suite " Result " ( fun ( ) -> let open Result in describe " ok " ( fun ( ) -> test " returns ok type " ( fun ( ) -> expect ( String . reverse " desserts " |> Result . ok ) ok |> toEqual ( let open Eq in result string string ) string ( Ok " stressed ) " ) ; test " returns ok type " ( fun ( ) -> expect ( List... |
let get_with_default value default_value = match value with Some value -> Some value | None -> default_value |
let make_error error_marker map_loc span message = let ( ) = error_marker . has_error <- true in Res_error { loc = map_loc span ; message } |
let has_directive ( ? prepend = false ) name directives = List . exists ( fun { item = { d_name = { item ; _ } ; _ } ; _ } -> match prepend with | true -> item = " bs " ^ name || item = " ppx " ^ name | false -> item = name ) directives |
let find_directive ( ? prepend = false ) name directives = match List . find ( fun { item = { d_name = { item ; _ } ; _ } ; _ } -> match prepend with | true -> item = " bs " ^ name || item = " ppx " ^ name | false -> item = name ) directives with | d -> Some d | exception Not_found -> None |
let find_argument name arguments = arguments |> Option . flat_map ( fun { item = arguments ; _ } -> match List . find ( fun ( { item = arg_name ; _ } , _ ) -> arg_name = name ) arguments with | a -> Some a | exception Not_found -> None ) |
let find_fragment_arguments ( directives : Graphql_ast . directive Source_pos . spanning list ) = match directives |> List . find ( fun d -> d . item . d_name . item = " arguments " ) with | { item = { d_arguments = Some arguments ; _ } ; _ } -> arguments . item |> List . fold_left ( fun acc -> function | { item = name... |
let get_ppx_as directives = match directives |> find_directive ~ prepend : true " As " with | None -> None | Some { item = { d_arguments ; _ } ; _ } -> ( match find_argument " type " d_arguments with | Some ( _ , { item = Iv_string type_name ; _ } ) -> Some type_name | _ -> None ) |
let rec unify_type ~ has_decoder error_marker as_record existing_record omit_future_value config span ty ( selection_set : selection list spanning option ) = match ty with | Ntr_nullable t -> Res_nullable { loc = config . map_loc span ; inner = unify_type ~ has_decoder error_marker as_record existing_record omit_future... |
let unify_operation error_marker config = function | { item = { o_type = Query ; o_selection_set ; _ } ; span } -> unify_selection_set error_marker false None config span ( query_type config . schema ) ( Some o_selection_set ) | { item = { o_type = Mutation ; o_selection_set ; _ } ; span } -> ( match mutation_type conf... |
type query_config = { schema : string option ; records : bool option ; objects : bool option ; inline : bool option ; template_tag : string option ; template_tag_location : string option ; template_tag_import : string option ; template_tag_return_type : string option ; tagged_template : bool option ; template_tag_is_fu... |
let get_template_tag query_config = match query_config . tagged_template with | Some false -> ( None , None , None ) | _ -> ( match ( get_with_default query_config . template_tag ( Ppx_config . template_tag ( ) ) , get_with_default query_config . template_tag_location ( Ppx_config . template_tag_location ( ) ) , get_wi... |
let get_config_arguments directives = let open Graphql_ast in directives |> filter_map ( function | { item = { d_name = { item = " ppxConfig " } ; d_arguments = Some { item = arguments } ; } ; } -> Some arguments | _ -> None ) |> List . concat |
let config_arguments_to_config existing_query_config directive_arguments : query_config = let open Graphql_ast in directive_arguments |> List . fold_left ( fun config -> function | { item = " schema " } , { item = Iv_string value } -> { config with schema = Some value } | { item = " records " } , { item = Iv_boolean va... |
let to_output_config ~ json_read_fn ~ map_loc ~ delimiter ~ document ( definition , query_config ) = let schema = Lazy . force ( Read_schema . get_schema ~ json_read_fn query_config . schema ) in let apollo_mode = match query_config . apollo_mode with | None -> Ppx_config . apollo_mode ( ) | Some apollo_mode -> apollo_... |
let rec generate_config ~ json_read_fn ~ map_loc ~ delimiter ~ initial_query_config document = match document with | ( Operation { item = { o_directives = directives } } as definition ) :: rest | ( Fragment { item = { fg_directives = directives } } as definition ) :: rest -> let query_config = directives |> get_config_... |
let rec unify_document_schema document = let error_marker = { Generator_utils . has_error = false } in match document with | ( Operation ( { item = { o_variable_definitions ; _ } ; _ } as op ) , config ) :: rest -> let structure = unify_operation error_marker config op in ( Def_operation { variable_definitions = o_vari... |
type exhaustive_flag = Exhaustive | Nonexhaustive |
type name = string Source_pos . spanning |
type field_result = | Fr_named_field of { name : string ; loc_key : loc ; loc : loc ; type_ : t ; arguments : Graphql_ast . arguments ; } | Fr_fragment_spread of { key : string ; loc : loc ; name : string ; type_name : string option ; arguments : string list ; } | Res_nullable of { loc : loc ; inner : t } | Res_array o... |
type definition = | Def_fragment of { name : string ; variable_definitions : Graphql_ast . variable_definitions Source_pos . spanning option ; has_error : bool ; fragment : Graphql_ast . fragment Source_pos . spanning ; type_name : string option ; inner : t ; } | Def_operation of { variable_definitions : Graphql_ast . ... |
let res_loc = function | Res_nullable { loc } | Res_array { loc } | Res_id { loc } | Res_string { loc } | Res_int { loc } | Res_float { loc } | Res_boolean { loc } | Res_raw_scalar { loc } | Res_poly_enum { loc } | Res_custom_decoder { loc } | Res_record { loc } | Res_object { loc } | Res_poly_variant_selection_set { l... |
let can_be_absent_as_field = function Res_nullable _ -> true | _ -> false |
type status = [ ` OK | ` Accepted | ` Created | ` Bad_request | ` Conflict | ` Not_found | ` Request_timeout ] |
type message = { severity : Logs . level ; text : string ; range : Locality . t option ; } |
type ( ' a , ' b ) t = { value : ( ' a , ' b ) Result . result ; status : status ; messages : message list ; } |
let write_severity ob x = let ( ) = Bi_outbuf . add_char ob ' " ' in let ( ) = Bi_outbuf . add_string ob ( Logs . level_to_string ( Some x ) ) in Bi_outbuf . add_char ob ' " ' |
let read_severity p lb = match Logs . level_of_string ( Yojson . Basic . read_string p lb ) with | Result . Ok ( Some x ) -> x | Result . Ok None -> raise ( Yojson . Json_error " Message of no severity " ) | Result . Error ( ` Msg x ) -> raise ( Yojson . Json_error ( " While reading severity : " ^ x ) ) |
let write_status ob = function | ` OK -> Bi_outbuf . add_string ob " 200 " | ` Accepted -> Bi_outbuf . add_string ob " 202 " | ` Created -> Bi_outbuf . add_string ob " 201 " | ` Bad_request -> Bi_outbuf . add_string ob " 400 " | ` Conflict -> Bi_outbuf . add_string ob " 409 " | ` Not_found -> Bi_outbuf . add_string ob ... |
let read_status p lb = match Yojson . Basic . read_int p lb with | 200 -> ` OK | 202 -> ` Accepted | 201 -> ` Created | 400 -> ` Bad_request | 409 -> ` Conflict | 404 -> ` Not_found | 408 -> ` Request_timeout | x -> raise ( Yojson . Json_error ( " Status " ^ string_of_int x " ^ is out of the scope of Kappa " ) ) |
let write_message ob { severity ; text ; range } = let ( ) = Bi_outbuf . add_char ob ' { ' in let ( ) = JsonUtil . write_field " severity " write_severity ob severity in let ( ) = JsonUtil . write_comma ob in let ( ) = JsonUtil . write_field " text " Yojson . Basic . write_string ob text in let ( ) = match range with |... |
let read_message p lb = let ( severity , text , range ) = Yojson . Basic . read_fields ( fun ( s , t , r ) key p lb -> if key = " severity " then ( read_severity p lb , t , r ) else if key = " text " then ( s , Yojson . Basic . read_string p lb , r ) else if key = " range " then ( s , t , Some ( Locality . read_range p... |
let print_message f { range ; text ; _ } = match range with | Some range -> Locality . print_annot Format . pp_print_string f ( text , range ) | None -> Format . pp_print_string f text |
let write_t write__ok write__error = fun ob -> function | { value = Result . Ok x ; status ; messages } -> Bi_outbuf . add_string ob " [ " \ Ok " , " ; \ write__ok ob x ; Bi_outbuf . add_char ob ' , ' ; write_status ob status ; Bi_outbuf . add_char ob ' , ' ; JsonUtil . write_list write_message ob messages ; Bi_outbuf ... |
let string_of_t write__ok write__error ( ? len = 1024 ) x = let ob = Bi_outbuf . create len in write_t write__ok write__error ob x ; Bi_outbuf . contents ob |
let read_t_content f p lb = let v = f p lb in let ( ) = JsonUtil . read_between_spaces Yojson . Basic . read_comma p lb in let s = read_status p lb in let ( ) = JsonUtil . read_between_spaces Yojson . Basic . read_comma p lb in ( v , s , Yojson . Basic . read_list read_message p lb ) |
let read_t read__ok read__error = fun p lb -> let aux_read_t closing p lb = Yojson . Basic . read_space p lb ; let out = Yojson . Basic . map_ident p ( fun s pos len -> Yojson . Basic . read_space p lb ; Yojson . Basic . read_comma p lb ; Yojson . Basic . read_space p lb ; match String . sub s pos len with | " Ok " -> ... |
let t_of_string read__ok read__error s = read_t read__ok read__error ( Yojson . Safe . init_lexer ( ) ) ( Lexing . from_string s ) |
let lift ( ? ok_status = ` OK ) ( ? error_status = ` Bad_request ) = function | Result . Ok _ as value -> { value ; status = ok_status ; messages = [ ] } | Result . Error _ as value -> { value ; status = error_status ; messages = [ ] } |
let fold ( ~ ok ' : ok -> ' a ) ( ~ error ' : error -> ' a ) : ( ' ok , ' error ) t -> ' a = function | { value = Result . Ok o ; _ } -> ok o | { value = Result . Error e ; _ } -> error e |
let bind : type ok a err . ? overwrite_status : status -> ? error_status : status -> ( ok -> ( a , err ) Result . result ) -> ( ok , err ) t -> ( a , err ) t = fun ? overwrite_status ( ? error_status = ` Bad_request ) ok -> function | { value = Result . Error _ ; _ } as e -> e | { value = Result . Ok o ; status ; messa... |
let map : type ok a err . ( ok -> a ) -> ( ok , err ) t -> ( a , err ) t = fun ok -> function | { value = Result . Ok o ; status ; messages } -> { value = Result . Ok ( ok o ) ; status ; messages } | { value = Result . Error _ ; _ } as e -> e |
let map2 : type a b ok err . ( a -> b -> ok ) -> ( a , err ) t -> ( b , err ) t -> ( ok , err ) t = fun f a b -> match a , b with | { value = Result . Ok a ; messages ; _ } , { value = Result . Ok b ; status ; messages = m ' } -> { value = Result . Ok ( f a b ) ; status ; messages = List . rev_append ( List . rev m ' )... |
let error ( ? status ` = Bad_request ) ( error ' : error ) : ( ' ok , ' error ) t = { value = Result . Error error ; status ; messages = [ ] ; } |
let ok ( ? status ` = OK ) ( ok : ' ok ) : ( ' ok , ' error ) t = { value = Result . Ok ok ; status ; messages = [ ] ; } |
type jobtype = Contract | FullTime | Temp ; ; type date = { month : int ; year : int } let compare_date x y = if ( x . year < y . year ) then - 1 else if ( x . year > y . year ) then 1 else if ( x . month < y . month ) then - 1 else if ( x . month > y . month ) then 1 else 0 class job_date ( x , y ) = object ( jd ) val... |
let string_of_unix_err err f p = Printf . sprintf " Unix_error ( % s , % s , % s ) " ( Unix . error_message err ) f p |
module HT = Hashtbl . Make ( Tls . Core . PreSharedKeyID ) |
let cache_psk , psk_cache = let cache = HT . create 7 in ( ( fun psk ed -> HT . add cache psk . Tls . Core . identifier ( psk , ed ) ) , HT . find_opt cache ) |
let ticket_cache = { Tls . Config . lookup = psk_cache ; ticket_granted = cache_psk ; lifetime = 300l ; timestamp = Ptime_clock . now } |
let serve_ssl port callback = let tag = " server " in X509_lwt . private_of_pems ~ cert : server_cert ~ priv_key : server_key >>= fun cert -> let hex = Cstruct . of_hex in let epoch = { Tls . Core . state = ` Established ; protocol_version = ` TLS_1_3 ; ciphersuite = ` DHE_RSA_WITH_AES_128_GCM_SHA256 ; peer_random = he... |
let echo_server port = serve_ssl port @@ fun ( ic , oc ) -> lines ic |> Lwt_stream . iter_s ( fun line -> yap ~ tag " : handler " ( " + " ^ string_of_int ( String . length line ) ) >>= fun ( ) -> Lwt_io . write_line oc line ) |
let ( ) = let port = try int_of_string Sys . argv . ( 1 ) with _ -> 4433 in Lwt_main . run ( echo_server port ) |
let ascii_printable c = let n = Char . code c in n >= 32 && n <= 127 |
let validate_some_text s = s <> " " && try String . iter ( fun c -> if not ( ascii_printable c ) then raise Exit ) s ; true with Exit -> false |
let validate_date x = let y = x . year in let m = x . month in let d = x . day in m >= 1 && m <= 12 && d >= 1 && ( let dmax = match m with 2 -> if y mod 4 = 0 && not ( y mod 100 = 0 ) || y mod 400 = 0 then 29 else 28 | 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31 | _ -> 30 in d <= dmax ) |
let compare_date a b = let c = compare a . year b . year in if c <> 0 then c else let c = compare a . month b . month in if c <> 0 then c else compare a . day b . day |
let validate_job x = match x . end_date with None -> true | Some end_date -> compare_date x . start_date end_date <= 0 |
let concatLongidents l1 l2 = let parts1 = Longident . flatten l1 in let parts2 = Longident . flatten l2 in match List . concat [ parts1 ; parts2 ] |> Longident . unflatten with | Some longident -> longident | None -> l2 |
let rec rewritePpatOpen longidentOpen pat = match pat . Parsetree . ppat_desc with | Ppat_array ( first :: rest ) -> { pat with ppat_desc = Ppat_array ( ( rewritePpatOpen longidentOpen first ) :: rest ) } | Ppat_tuple ( first :: rest ) -> { pat with ppat_desc = Ppat_tuple ( ( rewritePpatOpen longidentOpen first ) :: re... |
let rec rewriteReasonFastPipe expr = let open Parsetree in match expr . pexp_desc with | Pexp_apply ( { pexp_desc = Pexp_apply ( { pexp_desc = Pexp_ident { txt = Longident . Lident " . " } } | as op , [ Asttypes . Nolabel , lhs ; Nolabel , rhs ] ) ; pexp_attributes = subAttrs } , args ) -> let rhsLoc = { rhs . pexp_loc... |
let makeReasonArityMapper ~ forPrinter = let open Ast_mapper in { default_mapper with expr = begin fun mapper expr -> match expr with | { pexp_desc = Pexp_construct ( lid , args ) ; pexp_loc ; pexp_attributes } -> let newArgs = match args with | ( Some { pexp_desc = Pexp_tuple [ { pexp_desc = Pexp_tuple _ } as sp ] } )... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.