by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 04 12:51
    mergify[bot] labeled #799
  • Jun 04 12:51

    mergify[bot] on master

    Update monix to 3.2.2 (#799) (compare)

  • Jun 04 12:51
    mergify[bot] closed #799
  • Jun 04 12:46
    scala-steward opened #799
  • Jun 02 21:57

    mergify[bot] on master

    Update sbt-mdoc to 2.2.1 (#798)… (compare)

  • Jun 02 21:57
    mergify[bot] closed #798
  • Jun 02 21:52
    scala-steward synchronize #798
  • Jun 02 19:05
    mergify[bot] labeled #798
  • Jun 02 19:05
    mergify[bot] labeled #797
  • Jun 02 19:05

    mergify[bot] on master

    Update sbt-native-packager to 1… (compare)

  • Jun 02 19:05
    mergify[bot] closed #797
  • Jun 02 19:01
    scala-steward opened #798
  • Jun 02 19:01
    scala-steward opened #797
  • Jun 02 02:41
    scala-steward opened #796
  • May 31 02:56
    mergify[bot] labeled #795
  • May 31 02:56

    mergify[bot] on master

    Update sbt to 1.3.12 (#795) (compare)

  • May 31 02:56
    mergify[bot] closed #795
  • May 31 02:52
    scala-steward opened #795
  • May 29 18:56
    mergify[bot] labeled #794
  • May 29 18:56

    mergify[bot] on master

    Update sbt to 1.3.11 (#794) (compare)

Emanuel Couto
@unit73e
@VarunVats9 another nice to have is that these generic attributes (called type classes) give some guarantees that you can safely perform certain actions. For example, the combine method of SemiGroup is associative, so combining all elements of a SemiGroup can be executed in parallel (split, process, join).
With a regular List of something random you have no clue if you can execute an action on all elements in parallel or not.
hobovsky
@hobovsky
This is more or less another take on what I wanted to say above. For example a function which can reduce list of objects in parallel if objects are elements of some semigroup
Emanuel Couto
@unit73e
yes. Unfortunately most languages trying to copy functional programming because the cloud fad (which frankly is just distributed computing) want this but don't have this feature. But that's just me ranting.
Emanuel Couto
@unit73e

A Functor is a ubiquitous type class involving types that have one "hole", i.e. types which have the shape F[?]

I don't get it. What does "hole" mean here? One generic?

or a type parameter?
Emanuel Couto
@unit73e
I just don't understand how a "hole" could be a type parameter. Probably missing the equivalence.
Or the metaphor, if that's the point. Now I'm kind of curious.
hobovsky
@hobovsky
it has some particular name I cannot remember ATM, but it means that Functor is a generic type which depends on a type F, which is itself generic
For example, "this functor can operate on lists of things"
it's not important lists of what, just that it can be applied to lists
or another functor which can operate on Options of anything
Emanuel Couto
@unit73e
so I guess functor can operate on objects that have one type parameter but not zero or more than one.
and the "hole" is perhaps because you have to pass a type to make it a concrete type?
well I'm probably reading to much into it
hobovsky
@hobovsky
You can look at it as the fact that the functor is always "of something"
For example:
hobovsky
@hobovsky
let's say that you have some function, for example length takes in a string and returns int
and now, when you have "something of string", like, for example, a list of strings, or an optional of string, or such
if this something is a functor, it provides some means to reuse your function
so having function "string -> int" is enough to be able to reuse it as a function "List[String] -> List[Int]", or "Optional[String] -> Optional[Int]"
hobovsky
@hobovsky
that's why being a functoor is meaningful only for types which can hold something inside: because they can use a "primitive" function, or a function of "unwrapped" values, and apply it to itself being a kind of a wrapper
MercurieVV
@MercurieVV
Hi all
Can I somehow share my excersises progress? Dont see any button for this, but its mentioned on main page
hobovsky
@hobovsky
That was exactly my question too. I ended up taking a screenshot of the progress badge and sharing it :)
tlebrize
@tlebrize

I don't understand how

val xs1 = Set(3, 2, 1, 4, 5, 6, 7)
val ys1 = Set(7, 2, 1, 4, 5, 6, 3)
xs1.iterator.sameElements(ys1.iterator) should be (true)

but

val xt1 = Set(1, 2, 3)
val yt1 = Set(3, 2, 1)
xt1.iterator.sameElements(yt1.iterator) should be (false)

Both are in the wrong order ??

MercurieVV
@MercurieVV
@hobovsky I checked SE source code. Currently there's no ability to share user progress
tlebrize
@tlebrize
It seems that set ordering should just not be trusted. The last part of the Iterables chapter was really confusing to me because of this. I still don't understand what was the point it was trying to make ..
fengfengyuyu
@fengfengyuyu
how to solve true should be([213,231,213] )
fengfengyuyu
@fengfengyuyu

I don't understand how

val xs1 = Set(3, 2, 1, 4, 5, 6, 7)
val ys1 = Set(7, 2, 1, 4, 5, 6, 3)
xs1.iterator.sameElements(ys1.iterator) should be (true)

but

val xt1 = Set(1, 2, 3)
val yt1 = Set(3, 2, 1)
xt1.iterator.sameElements(yt1.iterator) should be (false)

Both are in the wrong order ??

xs1 and ys1 are both HashSet with same order , but xt1 and yt1 are just Set with different order.

I don't understand how

val xs1 = Set(3, 2, 1, 4, 5, 6, 7)
val ys1 = Set(7, 2, 1, 4, 5, 6, 3)
xs1.iterator.sameElements(ys1.iterator) should be (true)

but

val xt1 = Set(1, 2, 3)
val yt1 = Set(3, 2, 1)
xt1.iterator.sameElements(yt1.iterator) should be (false)

Both are in the wrong order ??

xs1 and ys1 are both HashSet with same order , but xt1 and yt1 are just Set with different order.

When the length of a Set is bigger than 4, this Set automatically is converted into a HashSet

tlebrize
@tlebrize
@fengfengyuyu Thanks !
ramakrishnaallam
@ramakrishnaallam

Hi guys.. I am looking for a solution in Scala for the below problem... I am thinking more from functional perspective..

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.

Write a function:

class Solution { public int solution(int N); }

that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.

Write an efficient algorithm for the following assumptions:

N is an integer within the range [1..2,147,483,647].

enaburekhan
@enaburekhan
Hi fam, pls I need help to enable provide answers to the below question of applying map method to higher order functions:

ef makeUpper(xs: List[String]) = xs map {
_.toUpperCase
}

def makeWhatEverYouLike(xs: List[String], sideEffect: String => String) =
xs map sideEffect

makeUpper(List("abc", "xyz", "123")) should be(
List(ABC, XYZ, 123): List[String]
)

makeWhatEverYouLike(List("ABC", "XYZ", "123"), { x =>
x.toLowerCase
}) should be(
List(abc, xyz, 123): List[String]
)

//using it inline
val myName = (name: String) => s"My name is $name"
makeWhatEverYouLike(List("John", "Mark"), myName) should be(
List(My name is John, My name is Mark): List[String]
)

List("Scala", "Erlang", "Clojure") map (_.length) should be(
List(5, 6, 7): List[Int]
)
Evaluation failed : Compilation Error ; ERROR -> postfix operator Mark needs to be enabled by making the implicit value scala.language.postfixOps visible. at [419, 419, 419]
9 contributors kiroco12 juanpedromoreno Yaskier raulraja hellrich josephpconley rzats laverboy andyscottEdit exercises

Scala Exercises is an Open Source project by 47 Degrees

Contributing · License

my answers seems incorrect here but looks correct on the code editor
hobovsky
@hobovsky
you have syntax error here: List(My name is John, My name is Mark): List[String]
enaburekhan
@enaburekhan
Thanks Man, I finally got it
Vladislav Golub
@vagola
Why i cant click run at scala-exercies web-site?
ml10
@ml10
Make sure you don’t have any script or cookie blockers running that might affect the page.
Dylan Martin
@dmarticus
fyi made this PR to fix an issue with a type signature error in circe-exercises: scala-exercises/exercises-circe#51
Dylan Martin
@dmarticus
one more tiny PR to fix a typo scala-exercises/exercises-circe#53
Thomas Young
@tyoung3
I was able to run the followng scala script on my Ubuntu 18.04.4 LTS only after adding the '-nc -howtorun:script' parameters:

!/bin/sh

exec scala -nc -howtorun:script "$0" "$@"
!#

object HelloWorld {
def main(args: Array[String]) {
println("Hello, World! " + args.toList)
}
}

Docs should be updated.

tyoung3@taos:scala$ time ./hw.sh
Hello, World! List()

real 0m4.035s
user 0m15.127s
sys 0m0.302s

Rackham
@imkrish7
val compareRationals: (Rational, Rational) => Int = __
what does that mean
Pedro
@ahncrist

About LazyList
Why when I try to execute a Scala Worksheet where I am testing :

val list = List(4, 6, 7, 8, 9, 13, 14)
val result = list.to(LazyList)

I get this;

result: scala.collection.immutable.LazyList[Int] = LazyList(<not computed>)

urbanchr
@urbanchr
I have installed Scala-exercises locally according to information in https://github.com/scala-exercises/scala-exercises. I managed to get the server up and running and see for example std-lib exercises inside my browser (localhost:9000). But when I try to run an exercise for example "true should be(_)" with the correct replacement, I receive a pop-up with "login with Github". Clicking on the corresponding button I get a "Missing code or state" message. Is there a way to get this running? Did I install everything correctly? Thanks!