1
1
Fork 0

Finished editing "Functional Programming"

Files containing only a newline at the end of the file indicate that I have reviewed that task and didn't need to change anything. The file now has a new timestamp indicating it has been reviewed.
This commit is contained in:
Bruce Eckel 2020-10-12 02:54:39 -06:00
parent 6d3c9e479f
commit a4b7513a49
11 changed files with 12 additions and 12 deletions

View File

@ -2,4 +2,4 @@
Implement a function named `demographic(people: List<Person>)` returning a Implement a function named `demographic(people: List<Person>)` returning a
`Map` where the key is age and the value is a list of names of people of that `Map` where the key is age and the value is a list of names of people of that
age. age.

View File

@ -1,3 +1,3 @@
## Building Maps (#2) ## Building Maps (#2)
Implement `groupBy()` using `getOrPut()`. Implement `groupBy()` using `getOrPut()`.

View File

@ -2,4 +2,4 @@
Implement `associateBy(keySelector: (T) -> R)` using `groupBy()`. If two Implement `associateBy(keySelector: (T) -> R)` using `groupBy()`. If two
elements have the same key produced by `keySelector` then the last one should elements have the same key produced by `keySelector` then the last one should
be added to the `Map`. be added to the `Map`.

View File

@ -1,4 +1,4 @@
## Folding Lists (#1) ## Folding Lists (#1)
Use `fold()` to finish the implementation of `size()` given in the starter Use `fold()` to finish the implementation of `size()` given in the starter
code. `size()` returns the number of elements in a `List`. code. `size()` returns the number of elements in a `List`.

View File

@ -1,3 +1,3 @@
## Folding Lists (#2) ## Folding Lists (#2)
Finish implementing `count()`, given in the starter code, using `fold()`. Finish implementing `count()`, given in the starter code, using `fold()`.

View File

@ -1,3 +1,3 @@
## Folding Lists (#3) ## Folding Lists (#3)
Implement `any()` using `fold()`. Implement `any()` using `fold()`.

View File

@ -3,5 +3,5 @@
The starter code provides a `Condition` class and a function The starter code provides a `Condition` class and a function
`Condition.combine()` that combines two conditions. There's also a skeleton `Condition.combine()` that combines two conditions. There's also a skeleton
for the `List<Condition>` extension function `combineAll()` that combines all for the `List<Condition>` extension function `combineAll()` that combines all
the conditions in the `List`. Complete the implementation using `reduce()`, conditions in the `List`. Complete the implementation using `reduce()`,
assuming the `List` is non-empty. assuming the `List` is non-empty.

View File

@ -1,3 +1,3 @@
## Higher-Order Functions (#1) ## Higher-Order Functions (#1)
Implement the `List<T>.map()` function from scratch. Implement the `List<T>.map()` function from scratch.

View File

@ -5,4 +5,4 @@ Rewrite the following function using a single call to `mapNotNull()`:
```kotlin ```kotlin
fun List<Int>.transform(): List<Int> = fun List<Int>.transform(): List<Int> =
filter { it % 2 == 0 }.map { it * it } filter { it % 2 == 0 }.map { it * it }
``` ```

View File

@ -8,4 +8,4 @@ Note the generic types `R?` (in `(Int, T) -> R?`) and `List<R>`. The `?` in
`R?` means the lambda's return type is nullable. `mapIndexedNotNull()` returns `R?` means the lambda's return type is nullable. `mapIndexedNotNull()` returns
a list of non-nullable elements, so the function return type is `List<R>`. To a list of non-nullable elements, so the function return type is `List<R>`. To
express that `R` is a non-nullable type, we specify a *constraint* on the express that `R` is a non-nullable type, we specify a *constraint* on the
generic type parameter: `R: Any`. generic type parameter: `R: Any`.

View File

@ -3,4 +3,4 @@
Implement `andThen()` to combine the actions of two functions. `f.andThen(g)` Implement `andThen()` to combine the actions of two functions. `f.andThen(g)`
returns a new function that first applies `f` and then applies `g` to the returns a new function that first applies `f` and then applies `g` to the
result: `{arg -> g(f(arg))}`. Define `andThen()` as an extension function on a result: `{arg -> g(f(arg))}`. Define `andThen()` as an extension function on a
function type. function type.