Skip to content

Commit

Permalink
move indexOf to List.Extra
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed May 5, 2021
1 parent 36dfa57 commit 56587ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 1 addition & 20 deletions src/Datalog.elm
Expand Up @@ -2,7 +2,7 @@ module Datalog exposing (Atom, Problem(..), Rule, Term, atom, headAtom, rule, ru

import Database exposing (Constant)
import Dict
import List.Extra exposing (foldrResult)
import List.Extra exposing (foldrResult, indexOf)


type Problem
Expand Down Expand Up @@ -91,25 +91,6 @@ bodyAtomToPlan bodyAtom =
atomToPlan atom_


indexOf : a -> List a -> Maybe Int
indexOf =
indexOfHelp 0


indexOfHelp : Int -> a -> List a -> Maybe Int
indexOfHelp idx item items =
case items of
[] ->
Nothing

first :: rest ->
if first == item then
Just idx

else
indexOfHelp (idx + 1) item rest


type Atom
= Atom String (List Term)

Expand Down
21 changes: 20 additions & 1 deletion src/List/Extra.elm
@@ -1,4 +1,4 @@
module List.Extra exposing (foldrResult)
module List.Extra exposing (foldrResult, indexOf)


foldrResult : (a -> b -> Result x b) -> b -> List a -> Result x b
Expand All @@ -19,3 +19,22 @@ foldrResultHelp fn soFar items =

Err problem ->
Err problem


indexOf : a -> List a -> Maybe Int
indexOf =
indexOfHelp 0


indexOfHelp : Int -> a -> List a -> Maybe Int
indexOfHelp idx item items =
case items of
[] ->
Nothing

first :: rest ->
if first == item then
Just idx

else
indexOfHelp (idx + 1) item rest

0 comments on commit 56587ad

Please sign in to comment.