juan_gandhi: (VP)
[personal profile] juan_gandhi
scala> def f(x:String) = null
f: (x: String)Null

scala> Some("abc") map f
res3: Option[Null] = Some(null)

Date: 2013-07-17 01:12 pm (UTC)
From: [identity profile] lomeo.livejournal.com
Это же map, всё правильно, он структуру должен сохранять. Тут flatMap нужен
scala> def f(x:String) = null
f: (x: String)Null

scala> Some("abc") flatMap (x => Option(f(x)))
res0: Option[Null] = None

Date: 2013-07-17 02:41 pm (UTC)
From: [identity profile] ivan-gandhi.livejournal.com
Я знаю, что можно сделать; но я не считаю, что Some(null) должен существовать в природе.

Date: 2013-07-17 02:43 pm (UTC)
From: [identity profile] lomeo.livejournal.com
Да я понял. Но на самом-то деле null не должен существовать в природе ;-)

Date: 2013-07-17 06:11 pm (UTC)

Date: 2013-07-17 08:13 pm (UTC)
From: [identity profile] aliaksandr famin (from livejournal.com)
А в чем проблема Some(null)? "Значение существует, но оно равно null" не эквивалентно "значения не существует".

Date: 2013-07-17 09:57 pm (UTC)
From: [identity profile] ivan-gandhi.livejournal.com
null - это не значение.

Date: 2013-07-18 11:55 am (UTC)
From: [identity profile] aliaksandr famin (from livejournal.com)
В наших реалиях null - это значение. До тех пор пока String - это ref, а не val.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718 192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 20th, 2025 09:00 am
Powered by Dreamwidth Studios