[Lift] Re: MappedString holding null
On Wed, Oct 14, 2009 at 8:40 PM, Naftoli Gugenheim wrote: > > > On Wed, Oct 14, 2009 at 11:08 PM, David Pollak < > feeder.of.the.be...@gmail.com> wrote: > >> >> >> On Wed, Oct 14, 2009 at 7:45 PM, Naftoli Gugenheim >> wrote: >> >>> >>> 1. Why does MappedString have members such as nonNull(in: String) >>> which don't depend on the MappedString's state? Shouldn't they be in a >>> singleton somewhere? >>> >> >> Maybe they should be, but are they hurting anything where they are? >> > Nope! Not complaining, just mentioning it. Are they meant to be public? Are > they used with any value for 'in' other than the field's own value? In other > words, would it make sense to take off the 'in' parameter, satisfying #1 and > #2. > If you change their signatures, it will break existing code. I probably added them when I needed some helper methods. You're welcome to add companions that read the current "is" value of the MappedString > >> >>> 2. It would be nice if there was a method like 'is' that would return >>> null as "". Actually for my particular use case where I'm testing >>> field.is.isEmpty it would be nice if it would have a method like >>> isEmpty that would return true if value==null || value.isEmpty. >>> >> >> You can (1) write a trait and mix it in or (2) write a subclass of >> MappedString and use that. >> >> >>> >>> >>> >> >> >> -- >> Lift, the simply functional web framework http://liftweb.net >> Beginning Scala http://www.apress.com/book/view/1430219890 >> Follow me: http://twitter.com/dpp >> Surf the harmonics >> >> >> > > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: MappedString holding null
On Wed, Oct 14, 2009 at 11:08 PM, David Pollak < feeder.of.the.be...@gmail.com> wrote: > > > On Wed, Oct 14, 2009 at 7:45 PM, Naftoli Gugenheim > wrote: > >> >> 1. Why does MappedString have members such as nonNull(in: String) >> which don't depend on the MappedString's state? Shouldn't they be in a >> singleton somewhere? >> > > Maybe they should be, but are they hurting anything where they are? > Nope! Not complaining, just mentioning it. Are they meant to be public? Are they used with any value for 'in' other than the field's own value? In other words, would it make sense to take off the 'in' parameter, satisfying #1 and #2. > > >> 2. It would be nice if there was a method like 'is' that would return >> null as "". Actually for my particular use case where I'm testing >> field.is.isEmpty it would be nice if it would have a method like >> isEmpty that would return true if value==null || value.isEmpty. >> > > You can (1) write a trait and mix it in or (2) write a subclass of > MappedString and use that. > > >> >> >> > > > -- > Lift, the simply functional web framework http://liftweb.net > Beginning Scala http://www.apress.com/book/view/1430219890 > Follow me: http://twitter.com/dpp > Surf the harmonics > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: MappedString holding null
Good point, thanks. On Wed, Oct 14, 2009 at 11:15 PM, Ross Mellgren wrote: > I've been using implicit extensions for this kind of thing, most recently > expanded error handling via Box. Like this: > implicit def mappedStringToMappedStringExtension(ms: MappedString): > MappedStringExtension = MappedStringExtension(ms) > case class MappedStringExtension(mappedString: MappedString) { > def orBlank: String = mappedString.is match { > case null => "" > case s => s > } > def isEmpty: Boolean = mappedString.is match { > case null => true > case s if s.length == 0 => true > case _ => false > } > } > -Ross > On Oct 14, 2009, at 11:08 PM, David Pollak wrote: > > > On Wed, Oct 14, 2009 at 7:45 PM, Naftoli Gugenheim > wrote: >> >> 1. Why does MappedString have members such as nonNull(in: String) >> which don't depend on the MappedString's state? Shouldn't they be in a >> singleton somewhere? > > Maybe they should be, but are they hurting anything where they are? > >> >> 2. It would be nice if there was a method like 'is' that would return >> null as "". Actually for my particular use case where I'm testing >> field.is.isEmpty it would be nice if it would have a method like >> isEmpty that would return true if value==null || value.isEmpty. > > You can (1) write a trait and mix it in or (2) write a subclass of > MappedString and use that. > >> > > > > -- > Lift, the simply functional web framework http://liftweb.net > Beginning Scala http://www.apress.com/book/view/1430219890 > Follow me: http://twitter.com/dpp > Surf the harmonics > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: MappedString holding null
I've been using implicit extensions for this kind of thing, most recently expanded error handling via Box. Like this: implicit def mappedStringToMappedStringExtension(ms: MappedString): MappedStringExtension = MappedStringExtension(ms) case class MappedStringExtension(mappedString: MappedString) { def orBlank: String = mappedString.is match { case null => "" case s => s } def isEmpty: Boolean = mappedString.is match { case null => true case s if s.length == 0 => true case _ => false } } -Ross On Oct 14, 2009, at 11:08 PM, David Pollak wrote: > > > On Wed, Oct 14, 2009 at 7:45 PM, Naftoli Gugenheim > wrote: > > 1. Why does MappedString have members such as nonNull(in: String) > which don't depend on the MappedString's state? Shouldn't they be in a > singleton somewhere? > > Maybe they should be, but are they hurting anything where they are? > > 2. It would be nice if there was a method like 'is' that would return > null as "". Actually for my particular use case where I'm testing > field.is.isEmpty it would be nice if it would have a method like > isEmpty that would return true if value==null || value.isEmpty. > > You can (1) write a trait and mix it in or (2) write a subclass of > MappedString and use that. > > > > > > > -- > Lift, the simply functional web framework http://liftweb.net > Beginning Scala http://www.apress.com/book/view/1430219890 > Follow me: http://twitter.com/dpp > Surf the harmonics > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: MappedString holding null
On Wed, Oct 14, 2009 at 7:45 PM, Naftoli Gugenheim wrote: > > 1. Why does MappedString have members such as nonNull(in: String) > which don't depend on the MappedString's state? Shouldn't they be in a > singleton somewhere? > Maybe they should be, but are they hurting anything where they are? > 2. It would be nice if there was a method like 'is' that would return > null as "". Actually for my particular use case where I'm testing > field.is.isEmpty it would be nice if it would have a method like > isEmpty that would return true if value==null || value.isEmpty. > You can (1) write a trait and mix it in or (2) write a subclass of MappedString and use that. > > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---