text stringlengths 0 601k |
|---|
let unwrapLazy t ~ default = match t with Ok t ' -> t ' | Error _ -> Lazy . force default |
let unwrapUnsafe t = Belt . Result . getExn t |
let unwrapError t ~ default = match t with Ok _ -> default | Error value -> value |
let map2 a b ~ f = match ( a , b ) b with | Ok a , Ok b -> Ok ( f a b ) b | Error a , _ -> Error a | _ , Error b -> Error b |
let values t = List . fold_right ( map2 ~ f ( : fun a b -> a :: b ) b ) b t ( Ok [ ] ) |
let combine ( l : ( ' ok , ' error ) ' error result list ) list : ( ' ok list , ' error ) ' error result = ( TableclothList . fold_right ~ f ( : fun ( accum : ( ' ok list , ' error ) ' error result ) result ( value : ( ' ok , ' error ) ' error result ) result : ( ' ok list , ' error ) ' error result -> map2 ~ f ( : fun... |
let map t ~ f = Belt . Result . map t f |
let mapError t ~ f = match t with Error error -> Error ( f error ) error | Ok value -> Ok value |
let toOption r = match r with Ok v -> Some v | Error _ -> None |
let andThen t ~ f = Belt . Result . flatMap t f |
let attempt f = match f ( ) with value -> Ok value | exception error -> Error error |
let tap t ~ f = match t with Ok a -> f a | _ -> ( ) |
let equal equalOk equalError a b = match ( a , b ) b with | Error a ' , Error b ' -> equalError a ' b ' | Ok a ' , Ok b ' -> equalOk a ' b ' | _ -> false |
let compare ( compareOk : ' ok -> ' ok -> int ) int ( compareError : ' error -> ' error -> int ) int ( a : ( ' ok , ' error ) ' error t ) t ( b : ( ' ok , ' error ) ' error t ) t : int = match ( a , b ) b with | Error a ' , Error b ' -> compareError a ' b ' | Ok a ' , Ok b ' -> compareOk a ' b ' | Error _ , Ok _ -> - 1... |
let ( |? ) t default = unwrap t ~ default |
let ( >>| ) t f = map t ~ f |
let ( >>= ) t f = andThen t ~ f |
type ( ' a , ' id ) ' id t = ( ' a , ' id ) ' id Belt . Set . t |
module Of ( M : TableclothComparator . S ) S = struct type nonrec t = ( M . t , M . identity ) identity t end |
let empty comparator = Belt . Set . make ~ id ( : Internal . toBeltComparator comparator ) comparator |
let singleton ( comparator : ( ' a , ' identity ) ' identity TableclothComparator . s ) s ( element : ' a ) ' a : ( ' a , ' identity ) ' identity t = Belt . Set . fromArray ~ id ( : Internal . toBeltComparator comparator ) comparator [ | element ] | |
let fromArray ( comparator : ( ' a , ' identity ) ' identity TableclothComparator . s ) s ( elements : ' a array ) array : ( ' a , ' identity ) ' identity t = Belt . Set . fromArray ~ id ( : Internal . toBeltComparator comparator ) comparator elements |
let fromList ( comparator : ( ' a , ' identity ) ' identity TableclothComparator . s ) s ( elements : ' a list ) list : ( ' a , ' identity ) ' identity t = Belt . Set . fromArray ~ id ( : Internal . toBeltComparator comparator ) comparator ( Array . of_list elements ) elements |
let ( { } . ? ) ( set : ( ' element , _ ) _ t ) t ( element : ' element ) ' element : bool = includes set element |
let filter s ~ f = Belt . Set . keep s f |
let partition s ~ f = Belt . Set . partition s f |
let find s ~ f = ( Belt . Set . toArray s . | Belt . Array . getBy ) getBy f |
let all s ~ f = Belt . Set . every s f |
let any s ~ f = Belt . Set . some s f |
let forEach s ~ f = Belt . Set . forEach s f |
let fold s ~ initial ~ f = Belt . Set . reduce s initial f |
module Poly = struct type identity type nonrec ' a t = ( ' a , identity ) identity t let fromArray ( type a ) a ( a : a array ) array : a t = Belt . Set . fromArray a ~ id : ( module struct type t = a type nonrec identity = identity let cmp = Pervasives . compare . | Obj . magic end ) let from_array = fromArray let fro... |
module Int = struct type nonrec t = Of ( OfTableclothInt ) OfTableclothInt . t let fromArray a = Poly . fromArray a . | Obj . magic let from_array = fromArray let empty = fromArray [ ] || let singleton a = fromArray [ | a ] | let fromList l = Array . of_list l . | fromArray let from_list = fromList end |
module String = struct type nonrec t = Of ( OfTableclothString ) OfTableclothString . t let fromArray a = Poly . fromArray a . | Obj . magic let from_array = fromArray let empty = fromArray [ ] || let singleton a = fromArray [ | a ] | let fromList l = Array . of_list l . | fromArray let from_list = fromList end |
type t = string type nonrec t = t let compare = compare end ) end |
let initialize length ~ f = Js . Array . joinWith " " ( Array . init length ( fun index -> f index |> TableclothChar . toString ) toString ) toString |
let get ( string : string ) string ( index : int ) int = string [ . index ] index |
let getAt ( string : string ) string ( ~ index : int ) int = if index < 0 || index >= String . length string then None else Some string [ . index ] index |
let ( [ ] . ? ) ( string : string ) string ( index : int ) int : char option = getAt string ~ index |
let fromArray characters = Js . Array . joinWith " " ( Array . map ( fun character -> TableclothChar . toCode character . | Js . String . fromCharCode ) characters ) |
let fromList t = Js . Array . joinWith " " ( Array . map ( fun character -> TableclothChar . toCode character . | Js . String . fromCharCode ) ( Array . of_list t ) t ) |
let fromChar c = TableclothChar . toCode c . | Js . String . fromCharCode |
let indexOf haystack needle : int option = let result = Js . String . indexOf needle haystack in if result = - 1 then None else Some result |
let indexOfRight haystack needle : int option = let result = Js . String . lastIndexOf needle haystack in if result = - 1 then None else Some result |
let isEmpty t = t = " " |
let uncons s = match s with | " " -> None | s -> Some ( s [ . 0 ] 0 , String . sub s 1 ( String . length s - 1 ) 1 ) 1 |
let dropLeft s ~ count = Js . String . substr ~ from : count s |
let dropRight s ~ count = if count < 1 then s else Js . String . slice ~ from : 0 ~ to_ ( :- count ) count s |
let split t ~ on = Js . String . split on t |> Array . to_list |
let endsWith t ~ suffix = Js . String . endsWith suffix t |
let startsWith t ~ prefix = Js . String . startsWith prefix t |
let padLeft string count ~ with_ = padLeft string count with_ |
let padRight string count ~ with_ = padRight string count with_ |
let toLowercase s = String . lowercase_ascii s |
let toUppercase s = String . uppercase_ascii s |
let isCapitalized s = s = String . capitalize_ascii s |
let includes t ~ substring = Js . String . includes substring t |
let repeat s ~ count = Js . String . repeat count s |
let reverse s = Js . Array . joinWith " " ( Js . Array . reverseInPlace ( Js . String . split " " s ) s ) s |
let toArray ( t : string ) string : char array = Js . String . castToArrayLike t . | Js . Array . from |> Js . Array . map ( fun characterString -> TableclothChar . fromString characterString . | Belt . Option . getExn ) |
let toList ( s : string ) string : char list = toArray s |> Belt . List . fromArray |
let slice ? to_ ( t : string ) string ~ from : string = Js . String . slice ~ from ~ to_ ( : Belt . Option . getWithDefault to_ ( length t ) t ) t t |
let insertAt t ~ index ~ value = Js . String . slice ~ from : 0 ~ to_ : index t ^ value ^ Js . String . sliceToEnd ~ from : index t |
let forEach t ~ f = Array . iter f ( toArray t ) t |
let fold t ~ initial ~ f = Belt . Array . reduce ( toArray t ) t initial f |
let equal = ( = ) |
type ( ' a , ' b ) ' b t = ' a * ' b |
let make a b = ( a , b ) b |
let fromArray array = match array with | [ ] || | [ | _ ] | -> None | [ | a ; b ] | -> Some ( a , b ) b | _ -> None |
let fromList list = match list with [ ] | [ _ ] -> None | a :: b :: _rest -> Some ( a , b ) b |
let first ( a , _ ) _ = a |
let second ( _ , b ) b = b |
let mapFirst ( a , b ) b ~ f = ( f a , b ) b |
let mapSecond ( a , b ) b ~ f = ( a , f b ) b |
let mapEach ( a , b ) b ~ f ~ g = ( f a , g b ) b |
let mapAll ( a1 , a2 ) a2 ~ f = ( f a1 , f a2 ) a2 |
let swap ( a , b ) b = ( b , a ) a |
let toArray ( a , b ) b = [ | a ; b ] | |
let toList ( a , b ) b = [ a ; b ] |
let equal equalFirst equalSecond ( a , b ) b ( a ' , b ' ) b ' = equalFirst a a ' && equalSecond b b ' |
let compare compareFirst compareSecond ( a , b ) b ( a ' , b ' ) b ' = match compareFirst a a ' with 0 -> compareSecond b b ' | result -> result |
type ( ' a , ' b , ' c ) ' c t = ' a * ' b * ' c |
let make a b c = ( a , b , c ) c |
let fromArray array = match array with | [ ] || | [ | _ ] | | [ | _ ; _ ] | -> None | [ | a ; b ; c ] | -> Some ( a , b , c ) c | _ -> None |
let fromList list = match list with | [ ] | [ _ ] | [ _ ; _ ] -> None | a :: b :: c :: _rest -> Some ( a , b , c ) c |
let first ( a , _ , _ ) _ = a |
let second ( _ , b , _ ) _ = b |
let third ( _ , _ , c ) c = c |
let initial ( a , b , _ ) _ = ( a , b ) b |
let tail ( _ , b , c ) c = ( b , c ) c |
let mapFirst ( a , b , c ) c ~ f = ( f a , b , c ) c |
let mapSecond ( a , b , c ) c ~ f = ( a , f b , c ) c |
let mapThird ( a , b , c ) c ~ f = ( a , b , f c ) c |
let mapEach ( a , b , c ) c ~ f ~ g ~ h = ( f a , g b , h c ) c |
let mapAll ( a1 , a2 , a3 ) a3 ~ f = ( f a1 , f a2 , f a3 ) a3 |
let rotateLeft ( a , b , c ) c = ( b , c , a ) a |
let rotateRight ( a , b , c ) c = ( c , a , b ) b |
let toArray ( a , b , c ) c = [ | a ; b ; c ] | |
let toList ( a , b , c ) c = [ a ; b ; c ] |
let equal equalFirst equalSecond equalThird ( a , b , c ) c ( a ' , b ' , c ' ) c ' = equalFirst a a ' && equalSecond b b ' && equalThird c c ' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.