add mapNotNull to ObjIterable with documentation

This commit is contained in:
sergeych committed 2025-12-12 13:48:02 +01:00
1 parent bce88ced43
commit 2737aaa14e
2 files changed
+31

No files matched your search

@@ -158,6 +158,23 @@ val ObjIterable by lazy {
ObjList(result)
}
addFnDoc(
name = "mapNotNull",
doc = "Transform elements by applying the given lambda unless it returns null.",
params = listOf(ParamDoc("transform")),
returns = type("lyng.List"),
isOpen = true,
moduleName = "lyng.stdlib"
) {
val fn = requiredArg<Statement>(0)
val result = mutableListOf<Obj>()
thisObj.toFlow(this).collect {
val transformed = fn.call(this, it)
if( transformed != ObjNull) result += transformed
}
ObjList(result)
}
addFnDoc(
name = "take",
doc = "Take the first N elements and return them as a list.",