update Grid.%() operator to return option
This commit is contained in:
parent
80f29ae00e
commit
c5c9b584c0
|
|
@ -36,7 +36,7 @@ let set_e grid point item =
|
||||||
else failwith "point out of bounds!"
|
else failwith "point out of bounds!"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let ( .%() ) = at_e
|
let ( .%() ) = at
|
||||||
let ( .%()<- ) = set_e
|
let ( .%()<- ) = set_e
|
||||||
|
|
||||||
let find (grid : 'a t) pred =
|
let find (grid : 'a t) pred =
|
||||||
|
|
@ -88,7 +88,7 @@ let draw grid printer =
|
||||||
let str = ref [] in
|
let str = ref [] in
|
||||||
iter grid (fun point ->
|
iter grid (fun point ->
|
||||||
let item = grid.%(point) in
|
let item = grid.%(point) in
|
||||||
let char = printer item in
|
let char = printer @@ Option.get_exn_or "iter is broken" item in
|
||||||
str := !str @ [ char ];
|
str := !str @ [ char ];
|
||||||
if point.x = grid.width - 1 then str := !str @ [ '\n' ]);
|
if point.x = grid.width - 1 then str := !str @ [ '\n' ]);
|
||||||
String.of_list !str
|
String.of_list !str
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ type 'a t [@@deriving show]
|
||||||
val at : 'a t -> Vec2.t -> 'a option
|
val at : 'a t -> Vec2.t -> 'a option
|
||||||
val at_e : 'a t -> Vec2.t -> 'a
|
val at_e : 'a t -> Vec2.t -> 'a
|
||||||
val set_e : 'a t -> Vec2.t -> 'a -> unit
|
val set_e : 'a t -> Vec2.t -> 'a -> unit
|
||||||
val ( .%() ) : 'a t -> Vec2.t -> 'a
|
val ( .%() ) : 'a t -> Vec2.t -> 'a option
|
||||||
val ( .%()<- ) : 'a t -> Vec2.t -> 'a -> unit
|
val ( .%()<- ) : 'a t -> Vec2.t -> 'a -> unit
|
||||||
val init : width:int -> height:int -> (Vec2.t -> 'a) -> 'a t
|
val init : width:int -> height:int -> (Vec2.t -> 'a) -> 'a t
|
||||||
val of_lines : (char -> 'a) -> string list -> 'a t
|
val of_lines : (char -> 'a) -> string list -> 'a t
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user