Source

spotlib / lib / xlist.mli

The default branch has multiple heads

Full commit
val iter_until : ('a -> [`Break of 'b | `Continue]) -> 'a list -> 'b option
val iteri : (int -> 'a -> 'b) -> 'a list -> unit
val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list

val from_to : int -> int -> int list
  (** [from_to f t = [f..t]] *)

val init_from_to : int -> int -> (int -> 'a) -> 'a list
  (** [init_from_to f t fn = [fn x | x <- [f..t]] *)

val find_opt : ('a -> bool) -> 'a list -> 'a option
val find_map_opt : ('a -> 'b option) -> 'a list -> 'b option
val assoc_all : 'a -> ('a * 'b) list -> 'b list

val filter_map : ('a -> 'b option) -> 'a list -> 'b list
val concat_map : ('a -> 'b list) -> 'a list -> 'b list
(** concatMap of Haskell. bind for the list monad. Non tail rec *)

val take : int -> 'a list -> 'a list
val drop : int -> 'a list -> 'a list
val span : ('a -> bool) -> 'a list -> 'a list * 'a list
val split_at : int -> 'a list -> 'a list * 'a list
val unique : 'a list -> 'a list (** Haskell's nub *)

val is_unique : ('a -> 'b) -> 'a list -> ('a * 'a) option
  (** Check the list is a unique list or not, wrt the key function. 
      If not, it returns a dupe example. 
      
      [is_unique fst [(1,2); (2,3); (4,5)] = None]
      [is_unique fst [(1,2); (2,3); (2,5)] = Some ( (2,3), (2,5) ) ]
  *)

val intersperse : 'a -> 'a list -> 'a list

val last : 'a list -> 'a
  (** raises Failure when the argument is [].
      [last [1;2;3] = 3]
  *)

val scani_left : 
  (int -> 'a -> 'b -> [< `Continue of 'a | `Stop of 'a ]) 
  -> 'a -> 'b list -> 'a
  (** [foldl] but stoppable *)