Skip to content

Commit

Permalink
Merge pull request #93 from pratikmota/list-support1
Browse files Browse the repository at this point in the history
Adding support for list type for "union" function
  • Loading branch information
refaktor authored Jan 10, 2024
2 parents 739decf + 9bd6169 commit c9fd885
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4925,9 +4925,33 @@ var builtins = map[string]*env.Builtin{
default:
return MakeArgError(ps, 2, []env.Type{env.BlockType}, "union")
}
// TODO-FIX1 add for list
case env.List:
switch secondBlock := arg1.(type) {
case env.Block:
mergedSlice := make([]env.Object, 0)
firtArgumentValue := s1
// If isAvailable is false then it is new value
isAvailable := false
for _, v1 := range secondBlock.Series.S {
isAvailable = false
for _, v2 := range firtArgumentValue.Data {
if env.RyeToRaw(v1) == v2 {
isAvailable = true
break
}
}
// If new value then add in List
if !isAvailable {
s1.Data = append(s1.Data, env.RyeToRaw(v1))
}
}
mergedSlice = append(mergedSlice, s1)
return *env.NewBlock(*env.NewTSeries(mergedSlice))
default:
return MakeArgError(ps, 2, []env.Type{env.BlockType}, "union")
}
default:
return MakeArgError(ps, 1, []env.Type{env.BlockType}, "union")
return MakeArgError(ps, 1, []env.Type{env.BlockType, env.ListType}, "union")
}

},
Expand Down

0 comments on commit c9fd885

Please sign in to comment.