summaryrefslogtreecommitdiff
path: root/lib/ur
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ur')
-rw-r--r--lib/ur/basis.urs7
-rw-r--r--lib/ur/list.ur25
-rw-r--r--lib/ur/list.urs6
3 files changed, 37 insertions, 1 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index a4872c32..883cc5b1 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -208,6 +208,10 @@ val blessEnvVar : string -> envVar
val checkEnvVar : string -> option envVar
val getenv : envVar -> transaction (option string)
+type meta
+val blessMeta : string -> meta
+val checkMeta : string -> option meta
+
(** JavaScript-y gadgets *)
@@ -813,7 +817,8 @@ val data_attrs : data_attr -> data_attr -> data_attr
val head : unit -> tag [Data = data_attr] html head [] []
val title : unit -> tag [Data = data_attr] head [] [] []
-val link : unit -> tag [Data = data_attr, Id = id, Rel = string, Typ = string, Href = url, Media = string] head [] [] []
+val link : unit -> tag [Data = data_attr, Id = id, Rel = string, Typ = string, Href = url, Media = string, Integrity = string, Crossorigin = string] head [] [] []
+val meta : unit -> tag [Nam = meta, Content = string, Id = id] head [] [] []
datatype mouseButton = Left | Right | Middle
diff --git a/lib/ur/list.ur b/lib/ur/list.ur
index 11895884..50764e46 100644
--- a/lib/ur/list.ur
+++ b/lib/ur/list.ur
@@ -434,6 +434,31 @@ fun drop [a] (n : int) (xs : list a) : list a =
fun splitAt [a] (n : int) (xs : list a) : list a * list a =
(take n xs, drop n xs)
+
+fun span [a] (f : a -> bool) (ls : list a) : list a * list a =
+ let
+ fun span' ls acc =
+ case ls of
+ [] => (rev acc, [])
+ | x :: xs => if f x then span' xs (x :: acc) else (rev acc, ls)
+ in
+ span' ls []
+ end
+
+fun groupBy [a] (f : a -> a -> bool) (ls : list a) : list (list a) =
+ let
+ fun groupBy' ls acc =
+ case ls of
+ [] => rev ([] :: acc)
+ | x :: xs =>
+ let
+ val (ys, zs) = span (f x) xs
+ in
+ groupBy' zs ((x :: ys) :: acc)
+ end
+ in
+ groupBy' ls []
+ end
fun mapXiM [m ::: Type -> Type] (_ : monad m) [a] [ctx ::: {Unit}] (f : int -> a -> m (xml ctx [] [])) : t a -> m (xml ctx [] []) =
let
diff --git a/lib/ur/list.urs b/lib/ur/list.urs
index 55068935..432d8c1a 100644
--- a/lib/ur/list.urs
+++ b/lib/ur/list.urs
@@ -105,3 +105,9 @@ val recToList : a ::: Type -> r ::: {Unit} -> folder r -> $(mapU a r) -> t a
val drop : t ::: Type -> int -> list t -> list t
val take : t ::: Type -> int -> list t -> list t
val splitAt : t ::: Type -> int -> list t -> list t * list t
+
+(** Longest prefix of elements that satisfy a predicate, returned along with the remaining suffix *)
+val span : a ::: Type -> (a -> bool) -> t a -> t a * t a
+
+(** Group a list into maximal adjacent segments where all elements compare as equal, according to the provided predicate. *)
+val groupBy : a ::: Type -> (a -> a -> bool) -> t a -> t (t a)