Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Christian Georgii
@cgeorgii
Alright, but let me know if you want me to take a stab at it ;)
Nikita Shilnikov
@flash-gordon
permission granted ;)
Christian Georgii
@cgeorgii
Cool, I will let you know
Christian Georgii
@cgeorgii
@flash-gordon Just opened a PR for this here: dry-rb/dry-types#277 :fireworks:
Let me know if you have any thoughts or questions.
Nikita Shilnikov
@flash-gordon
:+1: will check it out
Jules Ivanic
@guizmaii

Hi everyone,

First, I want to thanks all of the people working on this project ! It’s an awesome project ! :clap:

Second, is there any .sequence method proposed in dry-rb ?

sequence signature is: F[G[A]] -> G[F[A]]
Nikita Shilnikov
@flash-gordon
@guizmaii called w/o a block traverse acts as sequence https://github.com/dry-rb/dry-monads/blob/master/lib/dry/monads/list.rb#L263-L286
Jules Ivanic
@guizmaii
ok thanks :)
Jules Ivanic
@guizmaii
does it work on Ruby Array ?
Nikita Shilnikov
@flash-gordon
nope, we don't monkey patch core classes, it's against our philosophy :)
Jules Ivanic
@guizmaii
+1
awesome philosophy !
Jules Ivanic
@guizmaii
Do you thinks that this make sense: atomic_rows = Concurrent::AtomicReference.new(Dry::Monads::List.[]) ?
I need to update this list but my computation is parrallel
I’m very new to concurrency in Ruby :/

hum maybe this is better:

future_rows = Dry::Monads::List.[]
requests.find_in_baches { |data|
  future_rows += Task[:io] { compute_rows(data) } 
}

future_rows.traverse { |rows|
  …
}

WDYT ?

Nikita Shilnikov
@flash-gordon
future_rows = Concurrent::Array.new
requests.find_in_baches { |data|
  future_rows << Task[:io] { compute_rows(data) } 
}

Dry::Monads::List.coerce(future_rows.to_a).traverse { |rows|
  …
}
@guizmaii I think this one will work better
as in Monads::List isn't meant to be mutable
and, actually, you can use future_rows = []
since it's mutated from the same thread
Jules Ivanic
@guizmaii
Hum you’re right ! Thanks :)
is it coslty to coerce ?
if the array contains a lot of elements (< 100.000)
Nikita Shilnikov
@flash-gordon
not really
O(n) max
you can do List.new, it's O(1)
I bet traversing will be way more expensive tbh, it's not omptimized for long lists
otoh, it can be not that bad
Nikita Shilnikov
@flash-gordon
btw, if you use find_in_batches then future_rows.size will be equal total_rows / batch_size
which is better
I think you should give it a chance and see if something can be improved later
Jules Ivanic
@guizmaii
ok thanks for your precise answers ! :)
Jules Ivanic
@guizmaii
This message was deleted
Thanks for your help @flash-gordon ! 🙂
Nikita Shilnikov
@flash-gordon
sure, np
Grant Shangreaux
@gcentauri
is it counterproductive to add methods to structs? i'm primarily thinking of predicate type methods that would only return true or false based on the data the struct is holding
like, if i had a struct Fruit and if its name field was "banana" then my_fruit.banana? would return true. or... should there be helper functions like is_banana?(fruit)
Nikita Shilnikov
@flash-gordon
I do have a few methods like this, don't see anything harmful since it's not the same as having an AR-model :)
Grant Shangreaux
@gcentauri
haha thanks
ruby often feels like a slippery slope to me in those regards
Jules Ivanic
@guizmaii

Hi everyone,

I’m using the Task monad and I saw that there’s a pure function but there’s not its “dual” failed (equivalent of Concurent::Promise.reject).

How would you implement it ?

I don’t want to throw exception. Just create an immedialty failed Task
(throwing is expensive in JRuby)

is this something sensible:

    def failed(error)
      Dry::Monads::Task.new(Concurrent::Promise.reject(error))
    end

???

This message was deleted
Nikita Shilnikov
@flash-gordon
@guizmaii yeah, we should have it, no particular reason we don't have, just no one asked for it
Jules Ivanic
@guizmaii
If I have time I’ll push you a PR
Nikita Shilnikov
@flash-gordon
:+1: