Array.purs 596 Bytes
Newer Older
1
module Gargantext.Utils.Array (
2
    push
3
  , range) where
James Laver's avatar
James Laver committed
4

5
import Data.Array as A
6
import Data.Int as DI
James Laver's avatar
James Laver committed
7 8 9
import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2)

10 11
import Gargantext.Prelude

James Laver's avatar
James Laver committed
12 13 14 15
foreign import _push :: forall a. EffectFn2 (Array a) a Unit

push :: forall a. Array a -> a -> Effect Unit
push = runEffectFn2 _push
16 17


18 19 20 21
-- | Create an array containing a range of integers, with given step
range :: Int -> Int -> Int -> Array Int
range start end step = map (\i -> start + i*step) $ A.range 0 end'
  where
22
    end' = DI.floor $ (DI.toNumber $ end - start) / (DI.toNumber step)