about summary refs log tree commit diff
path: root/pkgs/profpatsch/dhallsh/List/filterOptional.dhall
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/profpatsch/dhallsh/List/filterOptional.dhall')
-rw-r--r--pkgs/profpatsch/dhallsh/List/filterOptional.dhall23
1 files changed, 23 insertions, 0 deletions
diff --git a/pkgs/profpatsch/dhallsh/List/filterOptional.dhall b/pkgs/profpatsch/dhallsh/List/filterOptional.dhall
new file mode 100644
index 00000000..810599b0
--- /dev/null
+++ b/pkgs/profpatsch/dhallsh/List/filterOptional.dhall
@@ -0,0 +1,23 @@
+let filterOptional
+	: ∀(a : Type) → ∀(b : Type) → (a → Optional b) → List a → List b
+	=   λ(a : Type)
+	  → λ(b : Type)
+	  → λ(f : a → Optional b)
+	  → λ(l : List a)
+	  → List/build
+		b
+		(   λ(list : Type)
+		  → λ(cons : b → list → list)
+		  → λ(nil : list)
+		  → List/fold
+			a
+			l
+			list
+			(   λ(x : a)
+			  → λ(xs : list)
+			  → Optional/fold b (f x) list (λ(opt : b) → cons opt xs) xs
+			)
+			nil
+		)
+
+in  filterOptional