arrays - How do I get a list item by index in elm? -


I've got a list, and now I want nth item in Haskell I !! , but I can not find the elm type of that.

Elm is not equal to it. You can of course apply it to yourself

(Note: this is not a "total" function, so it makes an exception when the index is out of range).

  infixl 9 !! (!!): [A] - & gt; Int - & gt; An xs !! n = head (drop n x)   

Using a data type, defining the total work would be a better way.

  infixl 9 !! (!!): [A] - & gt; Int - & gt; Maybe an xs !! N = if | N & lt; 0 - & gt; Nothing. Otherwise - & gt; Case (Xs, N) of ([], _) - & gt; Nothing (X :: Xs, 0) - & gt; Just X (_ :: xs, n) - & gt; Xs !! (N-1)    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -