idiomatic

What is an idiomatic way to create a zero-sized struct that can't be instantiated outside its crate?

我是研究僧i 提交于 2020-12-08 07:23:40
问题 I have something similar to this: mod private { // My crate pub struct A; impl A { pub fn new() -> Self { Self } // ... } } fn main() { // External code let obj = private::A::new(); let obj2 = private::A; } Currently, A doesn't need to store any internal state to do what I want it to (it's just being used as a placeholder in an enum), so I made it a zero-sized struct. However, that might change in the future, so I want to prevent code outside this crate from instantiating A without going

What is an idiomatic way to create a zero-sized struct that can't be instantiated outside its crate?

柔情痞子 提交于 2020-12-08 07:22:50
问题 I have something similar to this: mod private { // My crate pub struct A; impl A { pub fn new() -> Self { Self } // ... } } fn main() { // External code let obj = private::A::new(); let obj2 = private::A; } Currently, A doesn't need to store any internal state to do what I want it to (it's just being used as a placeholder in an enum), so I made it a zero-sized struct. However, that might change in the future, so I want to prevent code outside this crate from instantiating A without going

What is a good idiom for nested flatMaps in Java Reactor?

眉间皱痕 提交于 2020-07-21 04:21:29
问题 I inherited responsibility for a REST service written in Java using Spring and associated libraries including Reactor. For expensive operations like REST calls out or database operations the code is extensively wrapping the results in Reactor Mono. There are all sorts of things that need to be addressed in the code but one that keeps showing up is nested flatMap s over Mono s for sequences of expensive operations that end up up indented several levels deep into an unreadable mess. I find it

What is a good idiom for nested flatMaps in Java Reactor?

瘦欲@ 提交于 2020-07-21 04:21:02
问题 I inherited responsibility for a REST service written in Java using Spring and associated libraries including Reactor. For expensive operations like REST calls out or database operations the code is extensively wrapping the results in Reactor Mono. There are all sorts of things that need to be addressed in the code but one that keeps showing up is nested flatMap s over Mono s for sequences of expensive operations that end up up indented several levels deep into an unreadable mess. I find it

Will std::string end up being our compile-time string after all?

∥☆過路亽.° 提交于 2020-07-15 04:14:29
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Will std::string end up being our compile-time string after all?

丶灬走出姿态 提交于 2020-07-15 04:14:29
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Will std::string end up being our compile-time string after all?

老子叫甜甜 提交于 2020-07-15 04:14:24
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Idiomatic way to create n-ary cartesian product (combinations of several sets of parameters)

*爱你&永不变心* 提交于 2020-06-27 08:15:11
问题 To create all possible combinations of two sets of parameters and perform an action on them, you can do: setOf(foo, bar, baz).forEach { a -> setOf(0, 1).forEach { b -> /* use a and b */ } } However, if you have (potentially many) more parameters, this quickly turns into a pyramid of doom: setOf(foo, bar, baz).forEach { a -> setOf(0, 1).forEach { b -> setOf(true, false, null).forEach { c -> setOf("Hello,", "World!").forEach { d -> /* use a, b, c and d */ } } } } You could write this similarly