-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from dorian3343/main
Added list length component
- Loading branch information
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const n list<int> = [4,123,22,1121,215] | ||
component Main(start any) (stop any) { | ||
nodes { | ||
printer Printer<any> | ||
len Len<list<int>> | ||
} | ||
net { | ||
:start -> ($n -> len:data) | ||
len:res -> printer:data | ||
printer:sig -> :stop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package funcs | ||
|
||
import ( | ||
"context" | ||
"github.com/nevalang/neva/internal/runtime" | ||
) | ||
|
||
type listlen struct{} | ||
|
||
func (p listlen) Create(io runtime.FuncIO, _ runtime.Msg) (func(ctx context.Context), error) { | ||
dataIn, err := io.In.Port("data") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resOut, err := io.Out.Port("res") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return func(ctx context.Context) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case data := <-dataIn: | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case resOut <- runtime.NewIntMsg(int64(len(data.List()))): | ||
} | ||
} | ||
} | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters