Timeline for filter + map api design
Current License: CC BY-SA 4.0
        11 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 6, 2019 at 7:51 | vote | accept | CommunityBot | ||
| Mar 5, 2019 at 2:07 | comment | added | user290257 | 
        
            
    @KarlBielefeldt thanks, your java.util.Optional idea was a good one and worked for me, see my answer
        
     | 
|
| Mar 4, 2019 at 0:28 | comment | added | Karl Bielefeldt | 
        
            
    I'm not very familiar with Java, but I think you would want Optional.empty when you want to omit the item, and Optional.of to include it.
        
     | 
|
| Mar 3, 2019 at 22:42 | comment | added | user286798 | 
        
            
    so something like return new Optional<>()  (would essentially return false) and return new Optional<>(someValue) would represent true, and the value to be mapped to would be someValue? is that about right?
        
     | 
|
| Mar 1, 2019 at 19:54 | comment | added | Karl Bielefeldt | An option is a type in some libraries that indicates either the presence or absence of a value. For example, Optional in Java. | |
| Mar 1, 2019 at 18:37 | comment | added | user290257 | 
        
            
    you said use an empty array (or option) if you want to exclude the item - what do you mean by option?
        
     | 
|
| Mar 1, 2019 at 11:38 | comment | added | Bossie | 
        
            
    @MrCholo: flatMap maps elements to arrays, then flattens these arrays, where an empty array is flattened to nothing. Think of flatMap as a more general version of map, in that it can return 0 to N elements, instead of exactly 1 like map.
        
     | 
|
| Mar 1, 2019 at 9:23 | comment | added | user290257 | so the empty array represents false (filter it out)? Not sure I get it...what if the input array was made up of arrays? | |
| Mar 1, 2019 at 5:20 | comment | added | Karl Bielefeldt | It does coerce, but you're right that would be technically more correct. | |
| Mar 1, 2019 at 5:09 | comment | added | Bossie | 
        
            
    I believe it should be [x / 2], unless JavaScript does some kind of type coercion in this case.
        
     | 
|
| Mar 1, 2019 at 5:04 | history | answered | Karl Bielefeldt | CC BY-SA 4.0 |