Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
1b3766a2
Commit
1b3766a2
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Some extra library methods
parent
58dcce49
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
library/collection/List.scala
+26
-3
26 additions, 3 deletions
library/collection/List.scala
library/lang/Option.scala
+13
-2
13 additions, 2 deletions
library/lang/Option.scala
with
39 additions
and
5 deletions
library/collection/List.scala
+
26
−
3
View file @
1b3766a2
...
...
@@ -380,6 +380,8 @@ sealed abstract class List[T] {
case
_
=>
false
}
def
nonEmpty
=
!
isEmpty
// Higher-order API
def
map
[
R
](
f
:
T
=>
R
)
:
List
[
R
]
=
{
this
match
{
case
Nil
()
=>
Nil
[
R
]()
...
...
@@ -493,8 +495,28 @@ sealed abstract class List[T] {
_
==
this
.
filter
(
p
).
size
}
def
indexWhere
(
p
:
T
=>
Boolean
)
:
BigInt
=
{
this
match
{
case
Nil
()
=>
BigInt
(-
1
)
case
Cons
(
h
,
_
)
if
p
(
h
)
=>
BigInt
(
0
)
case
Cons
(
_
,
t
)
=>
val
rec
=
t
.
indexWhere
(
p
)
if
(
rec
>=
0
)
rec
+
BigInt
(
1
)
else
BigInt
(-
1
)
}}
ensuring
{
_
>=
BigInt
(
0
)
==
(
this
exists
p
)
}
// Translation to other collections
def
toSet
:
Set
[
T
]
=
foldLeft
(
Set
[
T
]()){
case
(
current
,
next
)
=>
current
++
Set
(
next
)
}
}
case
class
Cons
[
T
](
h
:
T
,
t
:
List
[
T
])
extends
List
[
T
]
case
class
Nil
[
T
]()
extends
List
[
T
]
object
List
{
@ignore
def
apply
[
T
](
elems
:
T*
)
:
List
[
T
]
=
{
...
...
@@ -544,10 +566,11 @@ object ListOps {
}
}
}
ensuring
{
isSorted
_
}
}
case
class
Cons
[
T
](
h
:
T
,
t
:
List
[
T
])
extends
List
[
T
]
case
class
Nil
[
T
]()
extends
List
[
T
]
def
toMap
[
K
,
V
](
l
:
List
[(
K
,
V
)])
:
Map
[
K
,
V
]
=
l
.
foldLeft
(
Map
[
K
,
V
]()){
case
(
current
,
(
k
,
v
))
=>
current
++
Map
(
k
->
v
)
}
}
// 'Cons' Extractor
object
::
{
...
...
This diff is collapsed.
Click to expand it.
library/lang/Option.scala
+
13
−
2
View file @
1b3766a2
...
...
@@ -3,6 +3,7 @@
package
leon.lang
import
leon.annotation._
import
leon.collection._
@library
sealed
abstract
class
Option
[
T
]
{
...
...
@@ -19,11 +20,11 @@ sealed abstract class Option[T] {
case
None
()
=>
default
}
def
orElse
(
or
:
Option
[
T
])
=
{
this
match
{
def
orElse
(
or
:
Option
[
T
])
=
{
this
match
{
case
Some
(
v
)
=>
this
case
None
()
=>
or
}}
ensuring
{
res
=>
(
this
.
isDefined
||
or
.
isDefined
)
==
res
.
isDefined
_
.
isDefined
==
this
.
isDefined
||
or
.
isDefined
}
def
isEmpty
=
this
match
{
...
...
@@ -61,6 +62,16 @@ sealed abstract class Option[T] {
def
exists
(
p
:
T
=>
Boolean
)
=
!
forall
(!
p
(
_
))
// Transformation to other collections
def
toList
:
List
[
T
]
=
this
match
{
case
None
()
=>
Nil
[
T
]()
case
Some
(
x
)
=>
List
(
x
)
}
def
toSet
:
Set
[
T
]
=
this
match
{
case
None
()
=>
Set
[
T
]()
case
Some
(
x
)
=>
Set
(
x
)
}
}
case
class
Some
[
T
](
v
:
T
)
extends
Option
[
T
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment