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