diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-06 13:43:46 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-06 14:23:39 +0200 |
| commit | 21ee11d3df3000a77d5b36d3c7e0a18d9a07d599 (patch) | |
| tree | 5c0be32fdecf596175c5f4504db1cda1ac0a6b21 /stdlib/common.milch | |
| parent | 64f2dbed84da98c4517cf725b088d870f4aadd98 (diff) | |
Add stdlib stuff, aoc22_1 example
Diffstat (limited to 'stdlib/common.milch')
| -rw-r--r-- | stdlib/common.milch | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/stdlib/common.milch b/stdlib/common.milch index b04cf37..b69452e 100644 --- a/stdlib/common.milch +++ b/stdlib/common.milch @@ -59,3 +59,43 @@ (let! flow (\[fs] (foldr compose id (reverse fs)))) (let! pipe (\[x fs] ((flow fs) x))) + +(let! leq? (\[a b] + (or? + (eq? a b) + (lt? a b)))) + +(let! rt? (compose not leq?)) +(let! req? (compose not lt?)) + +(let! max2 (\[a b] + (match (lt? a b) + true b + false a))) + +(let! max (\[vals] + (let! lazy v (head vals)) + (let! vs (tail vals)) + + (match vs + [] v + otherwise (max2 v (max vs))))) + +(let! split-by' (\[delim acc vals] + (let! lazy v (head vals)) + (let! vs (tail vals)) + + (match vs + [] (match v + delim [(reverse acc)] + otherwise [(prepend v (reverse acc))]) + otherwise (match v + delim (prepend (reverse acc) (split-by' delim [] vs)) + otherwise (split-by' delim (prepend v acc) vs))))) + +; split vector by delimiter +(let! split-by (\[delim vals] + (split-by' delim [] vals))) + +(let! print-fmt! (\![fstr args] + (print! (fmt fstr args)))) |
