src/Pure/library.ML
changeset 4916 fe8b0c82691b
parent 4893 df9d6eef16d5
child 4923 ec71c480e600
equal deleted inserted replaced
4915:5ff99bd60da9 4916:fe8b0c82691b
    82   val split_last: 'a list -> 'a list * 'a
    82   val split_last: 'a list -> 'a list * 'a
    83   val nth_update: 'a -> int * 'a list -> 'a list
    83   val nth_update: 'a -> int * 'a list -> 'a list
    84   val find_index: ('a -> bool) -> 'a list -> int
    84   val find_index: ('a -> bool) -> 'a list -> int
    85   val find_index_eq: ''a -> ''a list -> int
    85   val find_index_eq: ''a -> ''a list -> int
    86   val find_first: ('a -> bool) -> 'a list -> 'a option
    86   val find_first: ('a -> bool) -> 'a list -> 'a option
       
    87   val get_first: ('a -> 'b option) -> 'a list -> 'b option
    87   val flat: 'a list list -> 'a list
    88   val flat: 'a list list -> 'a list
    88   val seq: ('a -> unit) -> 'a list -> unit
    89   val seq: ('a -> unit) -> 'a list -> unit
    89   val separate: 'a -> 'a list -> 'a list
    90   val separate: 'a -> 'a list -> 'a list
    90   val replicate: int -> 'a -> 'a list
    91   val replicate: int -> 'a -> 'a list
    91   val multiply: 'a list * 'a list list -> 'a list list
    92   val multiply: 'a list * 'a list list -> 'a list list
   469 (*find first element satisfying predicate*)
   470 (*find first element satisfying predicate*)
   470 fun find_first _ [] = None
   471 fun find_first _ [] = None
   471   | find_first pred (x :: xs) =
   472   | find_first pred (x :: xs) =
   472       if pred x then Some x else find_first pred xs;
   473       if pred x then Some x else find_first pred xs;
   473 
   474 
       
   475 (*get first element by lookup function*)
       
   476 fun get_first _ [] = None
       
   477   | get_first f (x :: xs) =
       
   478       (case f x of
       
   479         None => get_first f xs
       
   480       | some => some);
       
   481 
   474 (*flatten a list of lists to a list*)
   482 (*flatten a list of lists to a list*)
   475 fun flat (ls: 'c list list) : 'c list = foldr (op @) (ls, []);
   483 fun flat (ls: 'c list list) : 'c list = foldr (op @) (ls, []);
   476 
   484 
   477 (*like Lisp's MAPC -- seq proc [x1, ..., xn] evaluates
   485 (*like Lisp's MAPC -- seq proc [x1, ..., xn] evaluates
   478   (proc x1; ...; proc xn) for side effects*)
   486   (proc x1; ...; proc xn) for side effects*)