Skip to content

Commit

Permalink
update examples for 0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Nov 15, 2016
1 parent 7813597 commit 065dbc2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 266 deletions.
2 changes: 1 addition & 1 deletion examples/Euler14.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ folder upper key value accum =


largest upper =
generates [1..upper]
generates (List.range 1 upper)
|> State.finalState (Dict.fromList [ ( 1, [ 1 ] ) ])
|> Dict.foldr (folder upper) Nothing

Expand Down
4 changes: 3 additions & 1 deletion examples/Euler92.elm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ solution n =
-}
cache : Dict Int Int
cache =
finalState Dict.empty (terminators [1..(step upperLimit)])
List.range 1 (step upperLimit)
|> terminators
|> finalState Dict.empty
|> Dict.insert 1 1
|> Dict.insert 89 89

Expand Down
45 changes: 2 additions & 43 deletions examples/Fibonacci.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Fibonacci exposing (..)
import State exposing (state, andThen, State)
import Dict exposing (Dict)
import Html exposing (Html, text)
import Trampoline exposing (..)


fib : Int -> Int
Expand Down Expand Up @@ -58,47 +57,7 @@ fibsHelper =


main =
-- fibs [0..9]
replicateM' 10 (State.state [ 2 ])
|> State.run 3
List.range 0 9
|> fibs
|> toString
|> text


tailRec : (a -> State s (Result a b)) -> a -> State s b
tailRec f x =
let
go ( x, s ) =
case State.run s (f x) of
( Err x, s ) ->
go ( x, s )

( Ok x, s ) ->
( x, s )
in
State.advance (\s -> go ( x, s ))


replicateM : Int -> State s a -> State s (List a)
replicateM n state =
let
go ( n, xs ) =
if n < 1 then
State.state (Ok xs)
else
State.map (\x -> Err ( n - 1, x :: xs )) state
in
tailRec go ( n, [] )


replicateM' : Int -> State s a -> State s (List a)
replicateM' n s =
let
go ( n, xs ) =
if n <= 0 then
done xs
else
jump (\_ -> go ( n - 1, State.map2 (::) s xs ))
in
go ( n, state [] )
|> evaluate
4 changes: 2 additions & 2 deletions examples/SieveOfEratosthenes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type alias Config =

range : Int -> Int -> Int -> List Int
range start stop step =
[0..((stop - start) // step)]
List.range 0 ((stop - start) // step)
|> List.map (\v -> v * step + start)


Expand Down Expand Up @@ -74,7 +74,7 @@ toNextIndex currentIndex sieve =
in
Array.filter predicate sieve
|> Array.get 0
|> (\m -> m `Maybe.andThen` identity)
|> (\m -> m |> Maybe.andThen identity)


primesUpTo : Int -> Array Int
Expand Down
214 changes: 0 additions & 214 deletions examples/Test.elm

This file was deleted.

9 changes: 4 additions & 5 deletions examples/elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
],
"exposed-modules": [],
"dependencies": {
"elm-community/list-extra": "3.1.0 <= v < 4.0.0",
"elm-lang/core": "4.0.1 <= v < 5.0.0",
"elm-lang/html": "1.1.0 <= v < 2.0.0",
"elm-lang/trampoline": "1.0.0 <= v < 2.0.0"
"elm-community/list-extra": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}

0 comments on commit 065dbc2

Please sign in to comment.