functional-programming

Range-v3's zip function works with temporaries coming from other Range-v3's functions but not with others

浪尽此生 提交于 2020-12-13 03:29:44
问题 (This is kind of a follow up to this other question.) Original question The following code works just fine #include <boost/range/adaptor/transformed.hpp> #include <cmath> #include <range/v3/view/zip.hpp> #include <string> #include <vector> int main() { auto vec1 = std::vector<int>{1,2,3}; auto vec2 = std::vector<std::string>{"uno","due","tre"}; auto sqrt = [](auto x){ return std::sqrt(x); }; auto vec3 = vec1 | boost::adaptors::transformed(sqrt); for (auto const& i : ranges::views::zip(vec1,

Can I print in Haskell the type of a polymorphic function as it would become if I passed to it an entity of a concrete type? [duplicate]

喜欢而已 提交于 2020-12-12 05:39:42
问题 This question already has answers here : Unifying c -> a -> b and (a -> b) -> c (3 answers) Closed 35 mins ago . Here's a function polymorphic in 3 types: :t (.) (.) :: (b -> c) -> (a -> b) -> a -> c and here a non polymorphic function: :t Data.Char.digitToInt Data.Char.digitToInt :: Char -> Int If we apply the former to the latter, we get a function polymorphic in 1 type: :t (.) Data.Char.digitToInt (.) Data.Char.digitToInt :: (a -> Char) -> a -> Int which means that (.) was "instantiated"

Buffer Operator on Java 8 Streams

帅比萌擦擦* 提交于 2020-12-07 05:02:55
问题 I am trying to write a java 8 stream collector which mirrors the functionality of rxjava buffer operator I have a working code for this: // This will gather numbers 1 to 13 and combine them in groups of // three while preserving the order even if its a parallel stream. final List<List<String>> triads = IntStream.range(1, 14) .parallel() .boxed() .map(Object::toString) .collect(ArrayList::new, accumulator, combiner); System.out.println(triads.toString()) The accumulator here is this: final

Buffer Operator on Java 8 Streams

徘徊边缘 提交于 2020-12-07 05:01:31
问题 I am trying to write a java 8 stream collector which mirrors the functionality of rxjava buffer operator I have a working code for this: // This will gather numbers 1 to 13 and combine them in groups of // three while preserving the order even if its a parallel stream. final List<List<String>> triads = IntStream.range(1, 14) .parallel() .boxed() .map(Object::toString) .collect(ArrayList::new, accumulator, combiner); System.out.println(triads.toString()) The accumulator here is this: final

Buffer Operator on Java 8 Streams

北城以北 提交于 2020-12-07 05:01:19
问题 I am trying to write a java 8 stream collector which mirrors the functionality of rxjava buffer operator I have a working code for this: // This will gather numbers 1 to 13 and combine them in groups of // three while preserving the order even if its a parallel stream. final List<List<String>> triads = IntStream.range(1, 14) .parallel() .boxed() .map(Object::toString) .collect(ArrayList::new, accumulator, combiner); System.out.println(triads.toString()) The accumulator here is this: final

Compare two lists to find date and time overlaps in Elixir

本秂侑毒 提交于 2020-12-02 00:20:42
问题 As part of some code that runs a booking system, we have a list of time_slots , which are tuples containing {start_time, end_time} . These are the available time slots that can be booked: time_slots = [ {~T[09:00:00], ~T[13:00:00]}, {~T[09:00:00], ~T[17:00:00]}, {~T[09:00:00], ~T[21:00:00]}, {~T[13:00:00], ~T[17:00:00]}, {~T[13:00:00], ~T[21:00:00]}, {~T[17:00:00], ~T[21:00:00]} ] Then we also have a list of bookings, which contains lists of tuples containing each {booking_start, booking_end}

Compare two lists to find date and time overlaps in Elixir

╄→гoц情女王★ 提交于 2020-12-02 00:18:37
问题 As part of some code that runs a booking system, we have a list of time_slots , which are tuples containing {start_time, end_time} . These are the available time slots that can be booked: time_slots = [ {~T[09:00:00], ~T[13:00:00]}, {~T[09:00:00], ~T[17:00:00]}, {~T[09:00:00], ~T[21:00:00]}, {~T[13:00:00], ~T[17:00:00]}, {~T[13:00:00], ~T[21:00:00]}, {~T[17:00:00], ~T[21:00:00]} ] Then we also have a list of bookings, which contains lists of tuples containing each {booking_start, booking_end}

Compare two lists to find date and time overlaps in Elixir

假如想象 提交于 2020-12-02 00:12:45
问题 As part of some code that runs a booking system, we have a list of time_slots , which are tuples containing {start_time, end_time} . These are the available time slots that can be booked: time_slots = [ {~T[09:00:00], ~T[13:00:00]}, {~T[09:00:00], ~T[17:00:00]}, {~T[09:00:00], ~T[21:00:00]}, {~T[13:00:00], ~T[17:00:00]}, {~T[13:00:00], ~T[21:00:00]}, {~T[17:00:00], ~T[21:00:00]} ] Then we also have a list of bookings, which contains lists of tuples containing each {booking_start, booking_end}

Compare two lists to find date and time overlaps in Elixir

会有一股神秘感。 提交于 2020-12-02 00:12:36
问题 As part of some code that runs a booking system, we have a list of time_slots , which are tuples containing {start_time, end_time} . These are the available time slots that can be booked: time_slots = [ {~T[09:00:00], ~T[13:00:00]}, {~T[09:00:00], ~T[17:00:00]}, {~T[09:00:00], ~T[21:00:00]}, {~T[13:00:00], ~T[17:00:00]}, {~T[13:00:00], ~T[21:00:00]}, {~T[17:00:00], ~T[21:00:00]} ] Then we also have a list of bookings, which contains lists of tuples containing each {booking_start, booking_end}

Compare two lists to find date and time overlaps in Elixir

帅比萌擦擦* 提交于 2020-12-02 00:07:54
问题 As part of some code that runs a booking system, we have a list of time_slots , which are tuples containing {start_time, end_time} . These are the available time slots that can be booked: time_slots = [ {~T[09:00:00], ~T[13:00:00]}, {~T[09:00:00], ~T[17:00:00]}, {~T[09:00:00], ~T[21:00:00]}, {~T[13:00:00], ~T[17:00:00]}, {~T[13:00:00], ~T[21:00:00]}, {~T[17:00:00], ~T[21:00:00]} ] Then we also have a list of bookings, which contains lists of tuples containing each {booking_start, booking_end}