Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jim Newton
clcompat
Commits
763754b7
Commit
763754b7
authored
Dec 03, 2020
by
Jim Newton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimization of withSetCollector
parent
4c522b51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
7 deletions
+6
-7
src/main/scala/accumulators/Accumulators.scala
src/main/scala/accumulators/Accumulators.scala
+6
-7
No files found.
src/main/scala/accumulators/Accumulators.scala
View file @
763754b7
// Copyright (c) 2019 EPITA Research and Development Laboratory
// Copyright (c) 2019
,20
EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
...
...
@@ -43,14 +43,13 @@ object Accumulators {
}
def
withSetCollector
[
A
](
f
:
(
A
=>
Unit
)
=>
Unit
)
:
Set
[
A
]
=
{
var
objects
:
Set
[
A
]
=
Set
()
// Thanks to Claudio Bley for this implementation.
// https://users.scala-lang.org/t/optional-parens/6938/11?u=jimka
val
objects
=
collection
.
mutable
.
Set
[
A
]()
def
collect
(
obj
:
A
)
:
Unit
=
{
objects
=
objects
+
obj
}
f
(
objects
.
add
)
f
(
collect
)
objects
objects
.
toSet
}
def
withNconc
[
A
](
f
:
(
List
[
A
]
=>
Unit
)
=>
Unit
)
:
List
[
A
]
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment