- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Is there a way to assign calculated values in guards to variables?
Howdy,
In pattern matching, I can assign the matched value to a variable:
{ case f @ Foo(_) => f.toString}
I'd like to be able to assign a computed value from a guard as well. For example:
{ case Some(id) if (record @ findRecord(id)).isDefined => record.name}
Is there any way to do this?
Thanks,
David
--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
In pattern matching, I can assign the matched value to a variable:
{ case f @ Foo(_) => f.toString}
I'd like to be able to assign a computed value from a guard as well. For example:
{ case Some(id) if (record @ findRecord(id)).isDefined => record.name}
Is there any way to do this?
Thanks,
David
--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp










Re: Is there a way to assign calculated values in guards to va
On Thu, Jan 15, 2009 at 1:19 AM, David Pollak
wrote:
> Howdy,
> In pattern matching, I can assign the matched value to a variable:
> {
> case f @ Foo(_) => f.toString
> }
> I'd like to be able to assign a computed value from a guard as well. For
> example:
> {
> case Some(id) if (record @ findRecord(id)).isDefined => record.name
> }
> Is there any way to do this?
Just to confirm the silence on the list since then: no, there's no way
to do this.
Cheers
Re: Is there a way to assign calculated values in guards to va
On Wed, Jan 21, 2009 at 10:39 PM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
Re: Is there a way to assign calculated values in guards to va
On Wed, Jan 21, 2009 at 2:21 PM, Stephane Le Dorze <stephane [dot] ledorze [at] gmail [dot] com> wrote:
Slick... I hadn't thought of this. It solves the problem. Thanks!
--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp