about summary refs log tree commit diff
path: root/pkgs/profpatsch/dhallsh/List/filterOptional.dhall
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2019-09-08 14:00:56 +0200
committerProfpatsch <mail@profpatsch.de>2019-09-08 14:06:07 +0200
commite711ceac63b2f7384151ba2753fe085f738e8b39 (patch)
tree9e86bb989596f57fc14b456406694fbb6ec5c936 /pkgs/profpatsch/dhallsh/List/filterOptional.dhall
Init: basic command line abstraction for fish’s complete
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