Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
short-exercises
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
Container 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
Tilman Voit
short-exercises
Commits
19c94620
Commit
19c94620
authored
5 years ago
by
Alexander Gehrke
Browse files
Options
Downloads
Patches
Plain Diff
[lec03] Add templates
parent
1c70c64a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+10
-6
10 additions, 6 deletions
README.md
src/main/scala/laziness/Stream.scala
+64
-0
64 additions, 0 deletions
src/main/scala/laziness/Stream.scala
src/test/scala/testutil/PendingIfUnimplemented.scala
+3
-0
3 additions, 0 deletions
src/test/scala/testutil/PendingIfUnimplemented.scala
with
77 additions
and
6 deletions
README.md
+
10
−
6
View file @
19c94620
...
...
@@ -7,10 +7,11 @@ Source templates for short exercises during the lecture, sometimes with tests.
Templates are within
`src/main/scala`
. Parts that you should complete are
usually marked with
`???`
.
| lecture | package |
|---------------------------------|-------------------------------------------------------------------|
| 2: Functional Data Structures |
[
`datastructures`
](
src/main/scala/datastructures
)
|
| 3: Error Handling |
[
`errors`
](
src/main/scala/errors
)
|
| lecture | package | tests
|---------------------------------|-------------------------------------------------------------------|----------------------------
| 2: Functional Data Structures |
[
`datastructures`
](
src/main/scala/datastructures
)
|
`testOnly datastructures.*`
| 3: Error Handling |
[
`errors`
](
src/main/scala/errors
)
|
`testOnly errors.*`
| 4: Laziness |
[
`laziness`
](
src/main/scala/laziness/
)
|
`testOnly laziness.*`
## Usage tips:
To keep your local solutions to the exercises when pulling from the repository,
...
...
@@ -19,6 +20,9 @@ use
git pull
--rebase
--autostash
```
This will keep both commited and uncommited changes.
If you are using Intellij IDEA, "rebase" is available as option in the update dialog and stashing is default.
If you are using Intellij IDEA, "rebase" is available as option in the update
dialog and stashing is default.
### Tests:
If you are using
`sbt`
directly, you can use
`testOnly`
to run a specific test suite (see table).
To automatically run tests, whenever a file changes, use
`~testOnly`
(
`~`
also works with other sbt commands).
This diff is collapsed.
Click to expand it.
src/main/scala/laziness/Stream.scala
0 → 100644
+
64
−
0
View file @
19c94620
package
laziness
sealed
trait
Stream
[
+A
]
{
import
Stream._
def
toList
:
List
[
A
]
=
???
def
take
(
n
:
Int
)
:
Stream
[
A
]
=
???
//This can be tailrecursive. Uncomment below to let the compiler check
//@annotation.tailrec
def
drop
(
n
:
Int
)
:
Stream
[
A
]
=
???
// Methods shown during lecture
def
headOption
:
Option
[
A
]
=
this
match
{
case
Cons
(
h
,
_
)
=>
Some
(
h
())
case
Empty
=>
None
}
def
exists
(
p
:
A
=>
Boolean
)
:
Boolean
=
this
match
{
case
Cons
(
x
,
xs
)
=>
p
(
x
())
||
xs
().
exists
(
p
)
case
Empty
=>
false
}
def
foldRight
[
B
](
z
:
=>
B
)(
f
:
(
A
,
=>
B
)
=>
B
)
:
B
=
this
match
{
case
Cons
(
x
,
xs
)
=>
f
(
x
(),
xs
().
foldRight
(
z
)(
f
))
case
Empty
=>
z
}
}
case
object
Empty
extends
Stream
[
Nothing
]
case
class
Cons
[
+A
](
h
:
()
=>
A
,
t
:
()
=>
Stream
[
A
])
extends
Stream
[
A
]
object
Stream
{
// companion object
def
fibs
:
Stream
[
Int
]
=
{
// tip: write a recursive def here and call it with some start values
???
}
def
unfold
[
A
,
S
](
z
:
S
)(
f
:
S
=>
Option
[(
A
,
S
)])
:
Stream
[
A
]
=
???
def
fibsViaUnfold
:
Stream
[
Int
]
=
???
// Methods shown during Lecture
def
cons
[
A
](
h
:
=>
A
,
t
:
=>
Stream
[
A
])
:
Stream
[
A
]
=
{
lazy
val
head
=
h
lazy
val
tail
=
t
Cons
(()
=>
head
,
()
=>
tail
)
}
def
empty
[
A
]
:
Stream
[
A
]
=
Empty
def
apply
[
A
](
as
:
A*
)
:
Stream
[
A
]
=
if
(
as
.
isEmpty
)
empty
else
cons
(
as
.
head
,
apply
(
as
.
tail
:
_
*
))
val
ones
:
Stream
[
Int
]
=
cons
(
1
,
ones
)
}
This diff is collapsed.
Click to expand it.
src/test/scala/testutil/PendingIfUnimplemented.scala
+
3
−
0
View file @
19c94620
...
...
@@ -2,6 +2,9 @@ package testutil
import
org.scalatest._
/**
* Mix into a test suite to mark tests for ??? methods as "pending" instead of "failed"
*/
trait
PendingIfUnimplemented
extends
TestSuiteMixin
{
this:
TestSuite
=>
abstract
override
def
withFixture
(
test
:
NoArgTest
)
:
Outcome
=
{
super
.
withFixture
(
test
)
match
{
...
...
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