1
1
# Region "Microsoft.VisualBasic::4adbfc2b363ce57d089db6a59ee7342d, R#\Runtime\Internal\internalInvokes\applys.vb"
2
2
3
- ' Author:
4
- '
5
-
6
-
7
-
8
- '
9
- ' Copyright (c) 2018 GPL3 Licensed
10
- '
11
- '
12
- ' GNU GENERAL PUBLIC LICENSE (GPL3)
13
- '
14
- '
15
- ' This program is free software: you can redistribute it and/or modify
16
- ' it under the terms of the GNU General Public License as published by
17
- ' the Free Software Foundation, either version 3 of the License, or
18
- ' (at your option) any later version.
19
- '
20
- ' This program is distributed in the hope that it will be useful,
21
- ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- ' GNU General Public License for more details.
24
- '
25
- ' You should have received a copy of the GNU General Public License
26
- ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
-
28
-
29
-
30
- ' /********************************************************************************/
31
-
32
- ' Summaries:
33
-
34
-
35
- ' Code Statistics:
36
-
37
- ' Total Lines: 649
38
- ' Code Lines: 428 (65.95%)
39
- ' Comment Lines: 135 (20.80%)
40
- ' - Xml Docs: 82.96%
41
- '
42
- ' Blank Lines: 86 (13.25%)
43
- ' File Size: 27.80 KB
44
-
45
-
46
- ' Module applys
47
- '
48
- ' Function: apply, checkInternal, lapply, (+3 Overloads) lapplyGeneralIDictionary, lapplyGeneralSequence
49
- ' lapplyPipelineStream, lapplyRNameIndex, parLapply, parSapply, sapply
50
- ' sapplyList, sapplySequence
51
- '
52
- '
53
- ' /********************************************************************************/
3
+ ' Author:
4
+ '
5
+
6
+
7
+
8
+ '
9
+ ' Copyright (c) 2018 GPL3 Licensed
10
+ '
11
+ '
12
+ ' GNU GENERAL PUBLIC LICENSE (GPL3)
13
+ '
14
+ '
15
+ ' This program is free software: you can redistribute it and/or modify
16
+ ' it under the terms of the GNU General Public License as published by
17
+ ' the Free Software Foundation, either version 3 of the License, or
18
+ ' (at your option) any later version.
19
+ '
20
+ ' This program is distributed in the hope that it will be useful,
21
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ ' GNU General Public License for more details.
24
+ '
25
+ ' You should have received a copy of the GNU General Public License
26
+ ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
+
28
+
29
+
30
+ ' /********************************************************************************/
31
+
32
+ ' Summaries:
33
+
34
+
35
+ ' Code Statistics:
36
+
37
+ ' Total Lines: 649
38
+ ' Code Lines: 428 (65.95%)
39
+ ' Comment Lines: 135 (20.80%)
40
+ ' - Xml Docs: 82.96%
41
+ '
42
+ ' Blank Lines: 86 (13.25%)
43
+ ' File Size: 27.80 KB
44
+
45
+
46
+ ' Module applys
47
+ '
48
+ ' Function: apply, checkInternal, lapply, (+3 Overloads) lapplyGeneralIDictionary, lapplyGeneralSequence
49
+ ' lapplyPipelineStream, lapplyRNameIndex, parLapply, parSapply, sapply
50
+ ' sapplyList, sapplySequence
51
+ '
52
+ '
53
+ ' /********************************************************************************/
54
54
55
55
# End Region
56
56
@@ -340,11 +340,17 @@ Namespace Runtime.Internal.Invokes
340
340
''' In the case of functions like +, %*%, the function name must be
341
341
''' backquoted or quoted.
342
342
''' </param>
343
+ ''' <param name="stream">
344
+ ''' run in lazy stream mode? default is not.
345
+ ''' </param>
343
346
''' <param name="envir"></param>
344
347
''' <returns></returns>
345
348
<ExportAPI( "sapply" )>
346
349
<RApiReturn( GetType (vector))>
347
- Public Function sapply(<RRawVectorArgument> X As Object , FUN As Object , envir As Environment) As Object
350
+ Public Function sapply(<RRawVectorArgument> X As Object , FUN As Object ,
351
+ Optional stream As Boolean = False ,
352
+ Optional envir As Environment = Nothing ) As Object
353
+
348
354
If X Is Nothing Then
349
355
Return New Object () {}
350
356
End If
@@ -366,10 +372,10 @@ Namespace Runtime.Internal.Invokes
366
372
If X.GetType.ImplementInterface( GetType (IDictionary)) Then
367
373
check = DirectCast (X, IDictionary).sapplyList(apply, nameVec, envir)
368
374
Else
369
- check = sapplySequence(X, apply, envir)
375
+ check = sapplySequence(X, apply, stream, envir)
370
376
End If
371
377
372
- If TypeOf check Is Message Then
378
+ If TypeOf check Is Message OrElse stream Then
373
379
Return check
374
380
Else
375
381
arrayVec = check
@@ -384,9 +390,8 @@ Namespace Runtime.Internal.Invokes
384
390
End If
385
391
End Function
386
392
387
- Private Function sapplySequence(x As Object , apply As RFunction, envir As Environment) As Object
393
+ Private Function sapplySequence(x As Object , apply As RFunction, stream As Boolean , envir As Environment) As Object
388
394
Dim seq As New List( Of Object )
389
- Dim value As Object
390
395
Dim argsPreviews As InvokeParameter()
391
396
Dim i As i32 = 1
392
397
Dim pull As IEnumerable( Of Object )
@@ -399,14 +404,27 @@ Namespace Runtime.Internal.Invokes
399
404
pull = REnv.asVector( Of Object )(x).AsObjectEnumerator
400
405
End If
401
406
402
- For Each d As Object In pull
403
- argsPreviews = invokeArgument(d, ++i )
404
- value = apply.Invoke(envir, argsPreviews)
407
+ Dim populateOut As Func( Of IEnumerable( Of Object )) =
408
+ Iterator Function () As IEnumerable( Of Object )
409
+ Dim value As Object
405
410
406
- If TypeOf value Is ReturnValue Then
407
- value = DirectCast (value, ReturnValue).value.Evaluate(envir)
408
- End If
411
+ For Each d As Object In pull
412
+ argsPreviews = invokeArgument(d, ++i)
413
+ value = apply.Invoke(envir, argsPreviews)
414
+
415
+ If TypeOf value Is ReturnValue Then
416
+ value = DirectCast (value, ReturnValue).value.Evaluate(envir)
417
+ End If
418
+
419
+ Yield value
420
+ Next
421
+ End Function
422
+
423
+ If stream Then
424
+ Return pipeline.CreateFromPopulator(populateOut())
425
+ End If
409
426
427
+ For Each value As Object In populateOut()
410
428
If Program.isException(value) Then
411
429
Return value
412
430
Else
0 commit comments