Sha256: 45d9c21e5f15e7bf5c93909c37af9810ebff8dd4af195d0e67830191bd02f461

Contents?: true

Size: 608 Bytes

Versions: 101

Compression:

Stored size: 608 Bytes

Contents

open Core.Std

let number s =
  let s' = String.filter ~f:Char.is_digit s in
  match String.length s' with
  | 10                            -> Some s'
  | 11 when String.get s' 0 = '1' -> Some (String.drop_prefix s' 1)
  | _                             -> None

let split_number s =
  (String.slice s 0 3, String.slice s 3 6, String.slice s 6 10)

let area_code s = 
  let open Option in (* >>| for Option *)
  number s >>| split_number >>| (fun (area, _, _) -> area)

let pretty s =
  let open Option in
  number s
  >>| split_number
  >>| fun (area, exch, subscr) -> sprintf "(%s) %s-%s" area exch subscr

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
trackler-1.0.0 tracks/ocaml/exercises/phone-number/example.ml