Last active
February 22, 2017 13:51
-
-
Save cvogt/65e33ed1f9de93c151e0ff145f8e74fb to your computer and use it in GitHub Desktop.
Revisions
-
cvogt revised this gist
Feb 22, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ case class Baz(bar: Bar) val b = Baz( Bar( "world" ) ) assert( b.copy( bar = b.bar.copy( str = "hello, " ++ b.bar.str ) ) // old: having to repeat repeat b and b.bar == b.copy( bar _= _.copy( str _= "hello, " ++ _ ) ) // new: short version via ~= operator for modification (alt syntax ~=) ) // new short version desugars to this (using access to default values): b.copy( bar = b.copy.bar.copy( str = "hello, " ++ b.copy.bar.copy.str ) ) @@ -22,6 +22,6 @@ b.copy( bar = b.copy.bar.copy( str = "hello, " ++ b.copy.bar.copy.str ) ) class Foo{ def str = "world" } assert( new Foo{ override str = "hello, " ++ super.str }.str // having to repeat `str` in override == new Foo{ override str _= "hello, " ++ _ }.str // new: modifying function based on parent value (alt syntax ~=) ) -
cvogt revised this gist
Feb 22, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ assert( Bar.apply.str == "test" ) // same for case classes via .apply method case class Baz(bar: Bar) val b = Baz( Bar( "world" ) ) assert( b.copy( bar = b.bar.copy( str = "hello, " ++ b.bar.str ) ) // old: having to repeat repeat b and b.bar == b.copy( bar ~= _.copy( str ~= "hello, " ++ _ ) ) // new: short version via ~= operator for modification ) // new short version desugars to this (using access to default values): -
cvogt revised this gist
Feb 22, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ assert( foo.str == "test" ) // new: named access to default values case class Bar(str: String = "test") assert( Bar.apply.str == "test" ) // same for case classes via .apply method // REPETIION-FREE .copy (aka lenses light) case class Baz(bar: Bar) val b = Baz( Bar( "world" ) ) -
cvogt revised this gist
Feb 22, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ assert( foo.str == "test" ) // new: named access to default values case class Bar(str: String = "test") assert( Bar.apply.str == "test" ) // same for case classes via .apply method // REPRTIION-FREE .copy (aka lenses light) case class Baz(bar: Bar) val b = Baz( Bar( "world" ) ) -
cvogt renamed this gist
Feb 22, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
cvogt created this gist
Feb 22, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ // DEFAULT VALUES def foo(str: String = "test") = ??? assert( foo.str == "test" ) // new: named access to default values case class Bar(str: String = "test") assert( Bar.apply.str == "test" ) // same for case classes via .apply method // REPITIION-FREE .copy (aka lenses light) case class Baz(bar: Bar) val b = Baz( Bar( "world" ) ) assert( b.copy( bar = b.bar.copy( str = "hello, " ++ b.bar.str ) ) // old: having to repeat repeat b.bar == b.copy( bar ~= _.copy( str ~= "hello, " ++ _ ) ) // new: short version via ~= operator for modification ) // new short version desugars to this (using access to default values): b.copy( bar = b.copy.bar.copy( str = "hello, " ++ b.copy.bar.copy.str ) ) // MODIFYING OVERRIDES class Foo{ def str = "world" } assert( new Foo{ override str = "hello, " ++ super.str }.str // having to repeat `str` in override == new Foo{ override str ~= "hello, " ++ _ }.str // new: modifying function based on parent value )