mirror of
https://github.com/jlengrand/FunctionalProgrammingScalaCoursera.git
synced 2026-03-10 08:21:22 +00:00
Adds exercises from week 5
This commit is contained in:
4
courses/.idea/modules/courses-build.iml
generated
4
courses/.idea/modules/courses-build.iml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="courses-build" external.linked.project.path="$MODULE_DIR$/../../project" external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" sbt.imports="_root_.sbt.plugins.IvyPlugin, _root_.sbt.plugins.JvmPlugin, _root_.sbt.plugins.CorePlugin, _root_.sbt.plugins.JUnitXmlReportPlugin, _root_.sbt.plugins.Giter8TemplatePlugin, sbt._, Keys._, dsl._" sbt.resolvers="https://repo1.maven.org/maven2/|maven|public, C:\Users\jll\.ivy2\cache|ivy|Local cache" type="SBT_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<module external.linked.project.id="courses-build" external.linked.project.path="$MODULE_DIR$/../../project" external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" sbt.imports="_root_.sbt.plugins.IvyPlugin, _root_.sbt.plugins.JvmPlugin, _root_.sbt.plugins.CorePlugin, _root_.sbt.plugins.JUnitXmlReportPlugin, _root_.sbt.plugins.Giter8TemplatePlugin, sbt._, Keys._, dsl._" sbt.resolvers="https://repo1.maven.org/maven2/|maven|public, C:\Users\jleng\.ivy2\cache|ivy|Local cache" type="SBT_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/../../project/target/idea-classes" />
|
||||
<output-test url="file://$MODULE_DIR$/../../project/target/idea-test-classes" />
|
||||
<exclude-output />
|
||||
|
||||
2
courses/.idea/modules/courses.iml
generated
2
courses/.idea/modules/courses.iml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="courses" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/../../target/scala-2.11/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/../../target/scala-2.11/test-classes" />
|
||||
<exclude-output />
|
||||
|
||||
10
courses/src/main/scala/week5/reduction.sc
Normal file
10
courses/src/main/scala/week5/reduction.sc
Normal file
@@ -0,0 +1,10 @@
|
||||
def mapFun[T, U](xs: List[T], f: T => U): List[U] =
|
||||
(xs foldRight List[U]())( (a, b) => f(a) :: b )
|
||||
|
||||
def lengthFun[T](xs: List[T]): Int =
|
||||
(xs foldRight 0)( (a, b) => b + 1)
|
||||
|
||||
|
||||
|
||||
lengthFun(List(3, 4, 5, 6))
|
||||
mapFun(List(3, 4, 5, 6), (x => 1)) // Couldn't find how to try it out
|
||||
Reference in New Issue
Block a user