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-2.0.5.4 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.5.3 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.5.2 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.5.1 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.5.0 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.4.0 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.9 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.8 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.7 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.6 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.5 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.4 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.3 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.2 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.1 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.3.0 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.2.0 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.1.2 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.1.1 tracks/ocaml/exercises/phone-number/example.ml
trackler-2.0.1.0 tracks/ocaml/exercises/phone-number/example.ml