From: Tuukka Lehtonen Date: Fri, 2 Nov 2018 13:26:39 +0000 (+0200) Subject: Added first and last functions to MList module X-Git-Tag: v1.43.0~136^2~299 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=083af64921be0776de06f568e616fb835b9dc23f;p=simantics%2Fplatform.git Added first and last functions to MList module gitlab #177 Change-Id: I6cdcbbbe91f5074747eba64a9439e4f3ed123d60 --- diff --git a/bundles/org.simantics.scl.runtime/scl/MList.scl b/bundles/org.simantics.scl.runtime/scl/MList.scl index fc4f94114..74b0c2482 100644 --- a/bundles/org.simantics.scl.runtime/scl/MList.scl +++ b/bundles/org.simantics.scl.runtime/scl/MList.scl @@ -24,6 +24,16 @@ removeLast l = if isEmpty l then Nothing else Just (remove l (Java.isub (size l) 1)) +"Returns the first element of a list" +@inline +first :: T a -> a +first s = get s 0 + +"Returns the last element of a list" +@inline +last :: T a -> a +last s = get s (Java.isub (size s) 1) + @inline iter :: (a -> ()) -> T a -> () iter f s = Iterator.iter f (iterator s)