Skip to content

Instantly share code, notes, and snippets.

@cvogt
Created August 6, 2015 23:02
Show Gist options
  • Save cvogt/d84914f8d9c4c908828e to your computer and use it in GitHub Desktop.
Save cvogt/d84914f8d9c4c908828e to your computer and use it in GitHub Desktop.
mapValues is lazy
scala> def foo = { val x = Map[Any,Any](() -> ()).mapValues(_ => ???); () }
foo: Unit
scala> foo
scala> def foo = { val x = Map[Any,Any](() -> ()).map(_ => ???); () }
foo: Unit
scala> foo
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:252)
...
@kevinmeredith
Copy link

This example made me poke around Haskell's Data.Map:

ghci>import Data.Map as M
ghci> let g = M.map (+ 5) $ M.singleton (\_ -> error) 10
ghci> M.size g
1
ghci> let res = M.map (+ 5) g
ghci> :t res
res :: Num b => Map (t -> [Char] -> a) b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment