Title: Ternary operator · Issue #19 · function61/gokit · GitHub
Open Graph Title: Ternary operator · Issue #19 · function61/gokit
X Title: Ternary operator · Issue #19 · function61/gokit
Description: Prototype: // 'ternary operator' func IfElseAssign[T any](val bool, ifTrue T, ifFalse T) T { if val { return ifTrue } else { return ifFalse } } // 'ternary operator' (lazy production of value) func IfElseAssignFn[T any](val bool, ifTrue ...
Open Graph Description: Prototype: // 'ternary operator' func IfElseAssign[T any](val bool, ifTrue T, ifFalse T) T { if val { return ifTrue } else { return ifFalse } } // 'ternary operator' (lazy production of value) func...
X Description: Prototype: // 'ternary operator' func IfElseAssign[T any](val bool, ifTrue T, ifFalse T) T { if val { return ifTrue } else { return ifFalse } } // 'ternary operator' (lazy productio...
Opengraph URL: https://github.com/function61/gokit/issues/19
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ternary operator","articleBody":"Prototype:\r\n\r\n```go\r\n// 'ternary operator'\r\nfunc IfElseAssign[T any](val bool, ifTrue T, ifFalse T) T {\r\n\tif val {\r\n\t\treturn ifTrue\r\n\t} else {\r\n\t\treturn ifFalse\r\n\t}\r\n}\r\n\r\n// 'ternary operator' (lazy production of value)\r\nfunc IfElseAssignFn[T any](val bool, ifTrue func() T, ifFalse func() T) T {\r\n\tif val {\r\n\t\treturn ifTrue()\r\n\t} else {\r\n\t\treturn ifFalse()\r\n\t}\r\n}\r\n\r\n// \"adapter\" for making values for `IfElseAssignFn` without having to type the full `func () string { return \"foo\" }`\r\nfunc fn[T any](val T) func() T {\r\n\treturn func() T { return val }\r\n}\r\n\r\nfunc main() {\r\n\tname := \"Joonas\"\r\n\tpowerEstimate := IfElseAssignFn(name == \"Joonas\", fn(9001), fn(3))\r\n\tpowerEstimate = IfElseAssign(name == \"Joonas\", 9001, 3)\r\n\tfmt.Printf(\"Power of %s = %d\\n\", name, powerEstimate)\r\n}\r\n```","author":{"url":"https://github.com/joonas-fi","@type":"Person","name":"joonas-fi"},"datePublished":"2023-03-06T10:43:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/19/gokit/issues/19"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:357e4ec5-8d42-1c42-aefe-1e477675b8d9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E88:280679:D209E:12FD61:6A4BBD76 |
| html-safe-nonce | d6732c747b3c1f3e8f9f5feb61ce53df0e2b8372d37063e59ae0f30d0b678494 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTg4OjI4MDY3OTpEMjA5RToxMkZENjE6NkE0QkJENzYiLCJ2aXNpdG9yX2lkIjoiMTM1MjU5NjI3OTczNzk1Nzc1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ea8a53a818603a6acc4cb324509a7105b79d9367bcf79dc1a5604ccfcd898843 |
| hovercard-subject-tag | issue:1611127646 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/function61/gokit/19/issue_layout |
| twitter:image | https://opengraph.githubassets.com/590684a978d392a79a8d1bde38bb77b0df990dde376134b160b3a2a25447a9c8/function61/gokit/issues/19 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/590684a978d392a79a8d1bde38bb77b0df990dde376134b160b3a2a25447a9c8/function61/gokit/issues/19 |
| og:image:alt | Prototype: // 'ternary operator' func IfElseAssign[T any](val bool, ifTrue T, ifFalse T) T { if val { return ifTrue } else { return ifFalse } } // 'ternary operator' (lazy production of value) func... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joonas-fi |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae1c14875555a1dd92bdef45baa6dd9aa796df891e4e471989f7117fe3139fc1 |
| turbo-cache-control | no-preview |
| go-import | github.com/function61/gokit git https://github.com/function61/gokit.git |
| octolytics-dimension-user_id | 22049800 |
| octolytics-dimension-user_login | function61 |
| octolytics-dimension-repository_id | 151857198 |
| octolytics-dimension-repository_nwo | function61/gokit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 151857198 |
| octolytics-dimension-repository_network_root_nwo | function61/gokit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b15c57117aeff522995a9578e1185f6c45d6c562 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width