digitalmars.D - [OT] C# 6.0 ?. null propagation operator
- weaselcat (7/7) Apr 20 2015 http://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_...
- Jakob Ovrum (4/11) Apr 20 2015 This is what I came up with for D:
- Atila Neves (3/17) Apr 20 2015 Here's mine:
- rumbu (9/29) Apr 20 2015 I fail to understand Atila example. Just to be sure:
- deadalnix (4/35) Apr 20 2015 These API look overly complex. Why not simply:
- rumbu (4/21) Apr 20 2015 Because CurrentUser, GetRole() and Name can also return null in
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/29) Apr 20 2015 The solution linked elsewhere in this thread solves that issue as well:
- deadalnix (2/26) Apr 20 2015 No, they all return a maybe, that is the nature of maybe monad.
- JT (2/5) Apr 20 2015 Where can I find this "maybe" monad implementation?
- Atila Neves (5/10) Apr 21 2015 In the Haskell prelude? :P
- Atila Neves (9/40) Apr 21 2015 I was trying to write a Maybe monad in D, not make it easy to use.
- Vladimir Panteleev (3/17) Apr 20 2015 Mine:
- thedeemon (3/6) Apr 20 2015 And we have a winner!
- Meta (4/11) Apr 20 2015 HS Teoh came up with a beautiful solution using opDispatch, but I
- Daniel N (2/16) Apr 20 2015 http://forum.dlang.org/thread/lnsc0c$1sip$1@digitalmars.com?page=6#post-...
http://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: b
Apr 20 2015
On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:http://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bThis is what I came up with for D: https://gist.github.com/JakobOvrum/7e3a7bc130ab7db28de3 Meh.
Apr 20 2015
On Monday, 20 April 2015 at 12:16:21 UTC, Jakob Ovrum wrote:On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:Here's mine: https://gist.github.com/atilaneves/727d63f0a7029032d7achttp://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bThis is what I came up with for D: https://gist.github.com/JakobOvrum/7e3a7bc130ab7db28de3 Meh.
Apr 20 2015
On Monday, 20 April 2015 at 15:37:02 UTC, Atila Neves wrote:On Monday, 20 April 2015 at 12:16:21 UTC, Jakob Ovrum wrote:I fail to understand Atila example. Just to be sure: var roleName = userManager.CurrentUser?.GetRole()?.Name; D (Jakob): auto roleName = userManager.getOrNull!("CurrentUser", "GetRole", "Name"); D (Atila): auto roleName = ?On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:Here's mine: https://gist.github.com/atilaneves/727d63f0a7029032d7achttp://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bThis is what I came up with for D: https://gist.github.com/JakobOvrum/7e3a7bc130ab7db28de3 Meh.
Apr 20 2015
On Monday, 20 April 2015 at 20:09:59 UTC, rumbu wrote:On Monday, 20 April 2015 at 15:37:02 UTC, Atila Neves wrote:These API look overly complex. Why not simply: maybe(userManager).CurrentUser.GetRole().Name ? Also, CAPITAL LETTER ARE THE BEST !On Monday, 20 April 2015 at 12:16:21 UTC, Jakob Ovrum wrote:I fail to understand Atila example. Just to be sure: var roleName = userManager.CurrentUser?.GetRole()?.Name; D (Jakob): auto roleName = userManager.getOrNull!("CurrentUser", "GetRole", "Name"); D (Atila): auto roleName = ?On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:Here's mine: https://gist.github.com/atilaneves/727d63f0a7029032d7achttp://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bThis is what I came up with for D: https://gist.github.com/JakobOvrum/7e3a7bc130ab7db28de3 Meh.
Apr 20 2015
On Monday, 20 April 2015 at 21:22:53 UTC, deadalnix wrote:On Monday, 20 April 2015 at 20:09:59 UTC, rumbu wrote:..Because CurrentUser, GetRole() and Name can also return null in this scenario.I fail to understand Atila example. Just to be sure: var roleName = userManager.CurrentUser?.GetRole()?.Name; D (Jakob): auto roleName = userManager.getOrNull!("CurrentUser", "GetRole", "Name"); D (Atila): auto roleName = ?These API look overly complex. Why not simply: maybe(userManager).CurrentUser.GetRole().Name ? Also, CAPITAL LETTER ARE THE BEST !
Apr 20 2015
On 04/20/2015 03:18 PM, rumbu wrote:On Monday, 20 April 2015 at 21:22:53 UTC, deadalnix wrote:The solution linked elsewhere in this thread solves that issue as well: http://forum.dlang.org/thread/lnsc0c$1sip$1 digitalmars.com?page=6#post-mailman.2584.1403213951.2907.digitalmars-d:40puremagic.com AliOn Monday, 20 April 2015 at 20:09:59 UTC, rumbu wrote:..Because CurrentUser, GetRole() and Name can also return null in this scenario.I fail to understand Atila example. Just to be sure: var roleName = userManager.CurrentUser?.GetRole()?.Name; D (Jakob): auto roleName = userManager.getOrNull!("CurrentUser", "GetRole", "Name"); D (Atila): auto roleName = ?These API look overly complex. Why not simply: maybe(userManager).CurrentUser.GetRole().Name ? Also, CAPITAL LETTER ARE THE BEST !
Apr 20 2015
On Monday, 20 April 2015 at 22:18:31 UTC, rumbu wrote:On Monday, 20 April 2015 at 21:22:53 UTC, deadalnix wrote:No, they all return a maybe, that is the nature of maybe monad.On Monday, 20 April 2015 at 20:09:59 UTC, rumbu wrote:..Because CurrentUser, GetRole() and Name can also return null in this scenario.I fail to understand Atila example. Just to be sure: var roleName = userManager.CurrentUser?.GetRole()?.Name; D (Jakob): auto roleName = userManager.getOrNull!("CurrentUser", "GetRole", "Name"); D (Atila): auto roleName = ?These API look overly complex. Why not simply: maybe(userManager).CurrentUser.GetRole().Name ? Also, CAPITAL LETTER ARE THE BEST !
Apr 20 2015
On Monday, 20 April 2015 at 21:22:53 UTC, deadalnix wrote:... maybe(userManager).CurrentUser.GetRole().Name ? ...Where can I find this "maybe" monad implementation?
Apr 20 2015
On Tuesday, 21 April 2015 at 02:00:49 UTC, JT wrote:On Monday, 20 April 2015 at 21:22:53 UTC, deadalnix wrote:In the Haskell prelude? :P There was a blog post about monads in D I can no longer find. Other than that the only other one I know of is the gist I posted. Atila... maybe(userManager).CurrentUser.GetRole().Name ? ...Where can I find this "maybe" monad implementation?
Apr 21 2015
On Monday, 20 April 2015 at 20:09:59 UTC, rumbu wrote:On Monday, 20 April 2015 at 15:37:02 UTC, Atila Neves wrote:I was trying to write a Maybe monad in D, not make it easy to use. An easy to use solution would probably make use of opDispatch. But...: auto roleName = userManager.bind!(a => a.CurrentUser.bind!(b => b.GetRole.bind!(c => c.Name); //roleName's type is Maybe!string. The only reason monads are readable in Haskell is due to "do" syntax sugar.On Monday, 20 April 2015 at 12:16:21 UTC, Jakob Ovrum wrote:I fail to understand Atila example. Just to be sure: var roleName = userManager.CurrentUser?.GetRole()?.Name; D (Jakob): auto roleName = userManager.getOrNull!("CurrentUser", "GetRole", "Name"); D (Atila): auto roleName = ?On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:Here's mine: https://gist.github.com/atilaneves/727d63f0a7029032d7achttp://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bThis is what I came up with for D: https://gist.github.com/JakobOvrum/7e3a7bc130ab7db28de3 Meh.
Apr 21 2015
On Monday, 20 April 2015 at 12:16:21 UTC, Jakob Ovrum wrote:On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:Mine: http://dump.thecybershadow.net/f8a172455ca239c35146f5dafdc7d1bc/test.dhttp://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bThis is what I came up with for D: https://gist.github.com/JakobOvrum/7e3a7bc130ab7db28de3 Meh.
Apr 20 2015
On Tuesday, 21 April 2015 at 03:35:49 UTC, Vladimir Panteleev wrote:On Monday, 20 April 2015 at 12:16:21 UTC, Jakob Ovrum wrote: Mine: http://dump.thecybershadow.net/f8a172455ca239c35146f5dafdc7d1bc/test.dAnd we have a winner!
Apr 20 2015
On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:http://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bHS Teoh came up with a beautiful solution using opDispatch, but I can't find the thread right now. That also reminds me that I meant to make a PR for it and completely forgot.
Apr 20 2015
On Monday, 20 April 2015 at 14:19:06 UTC, Meta wrote:On Monday, 20 April 2015 at 08:24:08 UTC, weaselcat wrote:http://forum.dlang.org/thread/lnsc0c$1sip$1 digitalmars.com?page=6#post-mailman.2584.1403213951.2907.digitalmars-d:40puremagic.comhttp://www.reddit.com/r/programming/comments/335b1s/the_new_operator_in_c_6/ of interesting note was the nim sample on how to implement the same thing in nim in 2 lines of code template `?.`(a, b): expr = if a != nil: a.b else: nil template `??`(a, b): expr = if a != nil: a else: bHS Teoh came up with a beautiful solution using opDispatch, but I can't find the thread right now. That also reminds me that I meant to make a PR for it and completely forgot.
Apr 20 2015