]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/MaximumBy.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / tests / org / simantics / scl / compiler / tests / scl / MaximumBy.scl
diff --git a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/MaximumBy.scl b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/MaximumBy.scl
new file mode 100644 (file)
index 0000000..c70c9da
--- /dev/null
@@ -0,0 +1,10 @@
+import "Prelude" hiding (maximumBy)\r
+\r
+maximumBy :: Ord b => (a -> b) -> [a] -> a\r
+maximumBy f = snd . foldl1 maxF . map (\x -> (f x, x))\r
+  where\r
+    maxF (a @ (aV,_)) (b @ (bV,_)) = if aV >= bV then a else b\r
+  \r
+main = maximumBy (`mod` 10) [1::Integer, 14, 23, 9, 14, 67]  \r
+--\r
+9
\ No newline at end of file