ocaml: phase 6 Option/Result/Bytes extensions (+9 tests, 439 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s
Option: join, to_result, some, none. Result: value, iter, fold. Bytes: length, get, of_string, to_string, concat, sub — thin alias of String (SX has no separate immutable byte type). Ordering fix: Bytes module placed after String so its closures capture String in scope. Earlier draft put Bytes before String which made String.* lookups fail with 'not a record/module' (treated as nullary ctor).
This commit is contained in:
@@ -274,6 +274,19 @@
|
||||
match o with
|
||||
| None -> []
|
||||
| Some x -> [x]
|
||||
|
||||
let join oo =
|
||||
match oo with
|
||||
| None -> None
|
||||
| Some inner -> inner
|
||||
|
||||
let to_result none_v o =
|
||||
match o with
|
||||
| None -> Error none_v
|
||||
| Some x -> Ok x
|
||||
|
||||
let some x = Some x
|
||||
let none = None
|
||||
end ;;
|
||||
|
||||
module Result = struct
|
||||
@@ -316,6 +329,21 @@
|
||||
match r with
|
||||
| Ok x -> Some x
|
||||
| Error _ -> None
|
||||
|
||||
let value r default =
|
||||
match r with
|
||||
| Ok x -> x
|
||||
| Error _ -> default
|
||||
|
||||
let iter f r =
|
||||
match r with
|
||||
| Ok x -> f x
|
||||
| Error _ -> ()
|
||||
|
||||
let fold ok_f err_f r =
|
||||
match r with
|
||||
| Ok x -> ok_f x
|
||||
| Error e -> err_f e
|
||||
end ;;
|
||||
|
||||
module String = struct
|
||||
@@ -334,6 +362,16 @@
|
||||
let index_of s sub = _string_index_of s sub
|
||||
end ;;
|
||||
|
||||
module Bytes = struct
|
||||
(* Thin alias of String — SX has no separate immutable byte type. *)
|
||||
let length s = String.length s
|
||||
let get s i = String.get s i
|
||||
let of_string s = s
|
||||
let to_string s = s
|
||||
let concat sep xs = String.concat sep xs
|
||||
let sub s i n = String.sub s i n
|
||||
end ;;
|
||||
|
||||
module Char = struct
|
||||
let code c = _char_code c
|
||||
let chr n = _char_chr n
|
||||
|
||||
Reference in New Issue
Block a user