Netflix very quiet on Mac OS

311

Only volume levels on Macs are the one at the top on the menubar, and the one within the browser, as part of Netflix.

Share:
311

Related videos on Youtube

Alfredo Gimenez
Author by

Alfredo Gimenez

Updated on September 18, 2022

Comments

  • Alfredo Gimenez
    Alfredo Gimenez almost 2 years

    I have code where a class can provide modified copies of itself, like so:

    case class A(i: Int, s: String) {
      def foo(ii: Int): A = copy(i = ii)
      def bar(ss: String): A = copy(s = ss)
    }
    

    I want to create a function that takes some optional arguments and creates these modified copies using these arguments if they are defined:

    def subA(a: A, oi: Option[Int] = None, os: Option[String] = None): A = {
      if (oi.isDefined && os.isDefined)
        a.foo(oi.get).bar(os.get)
      else if (oi.isDefined && !os.isDefined)
        a.foo(oi.get)
      else if (!oi.isDefined && os.isDefined)
        a.bar(os.get)
      else
        a
    }
    

    This is clearly not sustainable, as I add new optional arguments, I have to create cases for every combination of arguments...

    I also cannot do:

    a.foo(oi.getOrElse(a.i)).bar(os.getOrElse(a.s))
    

    Because in my actual code, if oi or os is not provided, I should NOT run their associated foo and bar functions. In other words, I have no default arguments for oi and os, rather their existence defines whether I should run certain functions at all.

    Current solution, extend the class:

    implicit class A_extended(a: A) {
      def fooOption(oi: Option[Int]): A = if (oi.isDefined) a.foo(oi.get) else a
      def barOption(os: Option[String]): A = if (os.isDefined) a.bar(os.get) else a
    }
    
    def subA(a: A, oi: Option[Int] = None, os: Option[String] = None): A = {
      a.fooOption(oi).barOption(os)
    }
    

    But this problem comes up often and it's a bit tedious to do this constantly, is there something like:

    // oi: Option[Int], foo: Int => A
    oi.ifDefinedThen(a.foo(_), a) // returns a.foo(oi.get) if oi is not None, else just a
    

    Or should I just extend Option to provide this functionality?

    • Russ Clarke
      Russ Clarke over 12 years
      Good point, I've added that to the bottom of my question.
  • Russ Clarke
    Russ Clarke over 12 years
    Disappointing but thanks anyway; I don't have the reputation required to vote you up, sorry.
  • Joseph
    Joseph over 12 years
    No worries. I would suggest external speakers to help push that level higher.
  • Alfredo Gimenez
    Alfredo Gimenez over 7 years
    This still requires enumerating out all combinations of a and b, which gets really ugly when I have many Option arguments.
  • Alfredo Gimenez
    Alfredo Gimenez over 7 years
    Yay, I used to wonder why Option was iterable, this is yet another great reason for it to be.
  • Nagarjuna Pamu
    Nagarjuna Pamu over 7 years
    @spiffman using simple map and flatMap composition . edited the answer
  • Nagarjuna Pamu
    Nagarjuna Pamu over 7 years
    @spiffman oi.map(a.foo).flatMap(a => os.map(a.bar)).getOrElse(a)
  • Alfredo Gimenez
    Alfredo Gimenez over 7 years
    The map / flatMap solution is incorrect unfortunately, try subA(new A(5, "five"), None, Some("six")). If the first option is None then the output doesn't get chained to the second option.
  • Alfredo Gimenez
    Alfredo Gimenez over 7 years
    This has nothing to do with my actual question, but wow, this is cool! My worry with something like updateInstance is that it changes the value of an immutable val, rendering it mutable.
  • sarveshseri
    sarveshseri over 7 years
    I thought that you wanted a generic copier for case classes and were trying to get it done using Options. Aso, If you do not need to update then you can just use copyInstance which reflects on the instace to capture its copy method and then uses it to create a copy with your updates fields.
  • Alfredo Gimenez
    Alfredo Gimenez over 7 years
    The copy functions were just to illustrate the problem of using multiple Option arguments to guard whether or not some functions are executed. Either way, I appreciate the submission, a lot of the reflection API documentation is dense, I learned more about reflection by reading your code :)
  • sarveshseri
    sarveshseri over 7 years
    Yup... your question looks pretty different from what I answered. Hope this answer helps some-one looking for such solution.
  • Alfredo Gimenez
    Alfredo Gimenez over 7 years
    You should submit it to StackOverflow Documentation, there is currently next to nothing in the Scala Reflection page: stackoverflow.com/documentation/scala/5824/reflection