GithubHelp home page GithubHelp logo

scala-exercises / exercises-scalatutorial Goto Github PK

View Code? Open in Web Editor NEW
163.0 17.0 384.0 591 KB

Exercises for the "Functional Programming Principles in Scala", part of the FP in Scala specialized program by EPFL.

License: Apache License 2.0

Scala 100.00%

exercises-scalatutorial's Introduction

Scala Exercises - Functional Programming Principles library


This repository hosts a library for the first course of the Scala MOOC ("Functional Programming Principles in Scala").

Run Locally

  • Clone this repository, compile and publish the project:
git clone [email protected]:scala-exercises/exercises-scalatutorial.git
cd exercises-scalatutorial/
sbt compile publishLocal # it is important to first run the `compile` command alone
  • Clone the evaluator and run it:
git clone [email protected]:scala-exercises/evaluator.git
cd evaluator/
sbt "project evaluator-server" run
  • Clone the scala-tutorial branch of our scala-exercises fork:
git clone -b scala-tutorial [email protected]:scalacenter/scala-exercises.git
  • Follow the database setup instructions given here

  • Add the following line the server/conf/application.dev.conf:

evaluator.secretKey="secretKey"
  • Run the server:
sbt -mem 1500 run

About Scala exercises

"Scala Exercises" brings exercises for the Stdlib, Cats, Shapeless and many other great libraries for Scala to your browser. Offering hundreds of solvable exercises organized into several categories covering the basics of the Scala language and it's most important libraries.

Scala Exercises is available at scala-exercises.org.

Contributing

Contributions welcome! Please join our Gitter channel to get involved, or visit our GitHub site.

License

Copyright (C) 2015-2016 47 Degrees, LLC. Reactive, scalable software solutions. http://47deg.com [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

exercises-scalatutorial's People

Contributors

47erbot avatar adrianrafo avatar alejandrohdezma avatar angoglez avatar batakpout avatar caileend avatar calvellido avatar dominv avatar exp0nge avatar fedefernandez avatar frosner avatar iselind avatar jacobarchambault avatar jonmcoe avatar juanmabm avatar juanpedromoreno avatar julienrf avatar kiroco12 avatar maureenelsberry avatar mdolata avatar mergify[bot] avatar michad avatar rvilla87 avatar sauntimo avatar scala-steward avatar sckelemen avatar sloshy avatar tschis avatar xhudik avatar xiaowei-zhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

exercises-scalatutorial's Issues

Apparent Error in Higher Order Functions section

https://github.com/scala-exercises/exercises-scalatutorial/blob/master/src/main/scala/scalatutorial/sections/HigherOrderFunctions.scala#L126-L138

If I try to run code like this, I get:

Welcome to Scala 2.12.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162-ea).
Type in expressions for evaluation. Or try :help.

scala> { def f(x1: Int, x2: Int) = x1 + x2 ; f }
<console>:12: error: missing argument list for method f
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `f _` or `f(_,_)` instead of `f`.
       { def f(x1: Int, x2: Int) = x1 + x2 ; f }
                                             ^

scala> 

list exercise error

According to https://github.com/scala-exercises/exercises-scalatutorial/blob/master/src/main/scala/scalatutorial/sections/StandardLibrary.scala#L72-L97

val nums = Nil.::(4).::(3).::(2).::(1)

nums match {
  // Lists of `Int` that starts with `1` and then `2`
  case 1 :: 2 :: xs => …
  // Lists of length 1
  case x :: Nil => …
  // Same as `x :: Nil`
  case List(x) => …
  // The empty list, same as `Nil`
  case List() =>
  // A list that contains as only element another list that starts with `2`
  case List(2 :: xs) => …
}

the last case of case List(2 :: xs) gives error because the inferred type is List[Int] but the case signature is expecting List[List[Int]]. Please correct me if I am wrong. If I am not then how should it be re-written?

type mismatch with example

Hi,

I am following this tutorial. Awesome work. However, I couldn't get this example working with the code provided.

trait Stream[+T] {
    def prepend[U >: T](elem: U) : Stream[U] = Stream.cons(elem, this)
}

Compiling the code above gives me error as following.

polymorphism.scala:15: error: type mismatch;
 found   : Stream[T]
 required: scala.collection.immutable.Stream[?]
           def prepend[U >: T](elem: U) : Stream[U] = Stream.cons(elem, this)

Did I miss something?

* def prepend [U >: T](elem: U): Stream[U] = Stream.cons(elem, this)

Factorial function seems to not work

I can't refer the variable result that's definitely in scope for the function for some reason.

Also, Looking at the source code, the code is actually different than the one shown here.

scala_exercises_factorial_error

Unexpected value in Lazy Evaluation exercise

Dear Team,

One of the exercises in Lazy Evaluation section returns odd result:
image

Same function in tests:

class LazyEvaluationSpec extends RefSpec with Checkers {

  def `check lazy list range`(): Unit =
    check(Test.testSuccess(LazyEvaluation.llRangeExercise _, 3 :: HNil)

I can't press run button

When i try to solve the exercise, i can't press run button, neither in the mobile browser nor in the computer browser.

That could be happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.