Skip to content

Commit

Permalink
updated bimapN
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTrew committed Jun 20, 2020
1 parent 2a702cc commit 1a86eff
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 52 deletions.
11 changes: 11 additions & 0 deletions AS Prelude MD/bimapN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```applescript
-- bimapN :: (a -> b) -> (c -> d) -> TupleN -> TupleN
on bimapN(f, g, tplN)
set z to length of tplN
set k1 to (z - 1) as string
set k2 to z as string
insertDict(k2, mReturn(g)'s |λ|(Just of lookupDict(k2, tplN)), ¬
insertDict(k1, mReturn(f)'s |λ|(Just of lookupDict(k1, tplN)), tplN))
end bimapN
```
4 changes: 2 additions & 2 deletions AS Prelude MD/cartesianProduct.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
```applescript
-- cartesianProduct :: [a] -> [b] -> [(a, b)]
-- cartesianProduct :: [a] -> [b] -> [[a, b]]
on cartesianProduct(xs, ys)
script
on |λ|(x)
script
on |λ|(y)
{Tuple(x, y)}
{x, y}
end |λ|
end script
concatMap(result, ys)
Expand Down
4 changes: 2 additions & 2 deletions AS Prelude MD/groupSortOn.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
```

```applescript
-- groupSortOn :: Ord b => (a -> b) -> [a] -> [a]
-- groupSortOn :: Ord b => [((a -> b), Bool)] -> [a] -> [a]
-- groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
-- groupSortOn :: Ord b => [((a -> b), Bool)] -> [a] -> [[a]]
on groupSortOn(f, xs)
script keyBool
on |λ|(a, x)
Expand Down
2 changes: 1 addition & 1 deletion AS Prelude MD/sqrt.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```applescript
-- sqrt :: Num -> Num
on sqrt(n)
if n ≥ 0 then
if 0 <= n then
n ^ (1 / 2)
else
missing value
Expand Down
2 changes: 1 addition & 1 deletion AS Prelude MD/tupleFromList.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on tupleFromList(xs)
end if
script kv
on |λ|(a, x, i)
insertMap(a, (i as string), x)
insertDict((i as string), x, a)
end |λ|
end script
foldl(kv, {type:"Tuple" & strSuffix}, xs) & {length:lng}
Expand Down
52 changes: 16 additions & 36 deletions asPrelude.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ on bimapLR(f, g)
end script
end bimapLR

-- bimapN :: (a -> b) -> (c -> d) -> TupleN -> TupleN
on bimapN(f, g, tplN)
set z to length of tplN
set k1 to (z - 1) as string
set k2 to z as string

insertDict(k2, mReturn(g)'s |λ|(Just of lookupDict(k2, tplN)), ¬
insertDict(k1, mReturn(f)'s |λ|(Just of lookupDict(k1, tplN)), tplN))
end bimapN

-- bind (>>=) :: Monad m => m a -> (a -> m b) -> m b
on bind(m, mf)
set c to class of m
Expand Down Expand Up @@ -592,13 +602,13 @@ on bulleted(strIndent, s)
unlines(map(go, paragraphs of s))
end bulleted

-- cartesianProduct :: [a] -> [b] -> [(a, b)]
-- cartesianProduct :: [a] -> [b] -> [[a, b]]
on cartesianProduct(xs, ys)
script
on |λ|(x)
script
on |λ|(y)
{Tuple(x, y)}
{x, y}
end |λ|
end script
concatMap(result, ys)
Expand Down Expand Up @@ -880,36 +890,6 @@ on curry(f)
end script
end curry

-- curry2 :: ((a, b) -> c) -> a -> b -> c
on curry2(f)
script
on |λ|(a)
script
on |λ|(b)
|λ|(a, b) of mReturn(f)
end |λ|
end script
end |λ|
end script
end curry

-- curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
on curry3(f)
script
on |λ|(a)
script
on |λ|(b)
script
on |λ|(c)
|λ|(a, b, c) of mReturn(f)
end |λ|
end script
end |λ|
end script
end |λ|
end script
end curry3

-- cycle :: [a] -> Generator [a]
on cycle(xs)
script
Expand Down Expand Up @@ -2365,8 +2345,8 @@ on groupBy(f, xs)
end if
end groupBy

-- groupSortOn :: Ord b => (a -> b) -> [a] -> [a]
-- groupSortOn :: Ord b => [((a -> b), Bool)] -> [a] -> [a]
-- groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
-- groupSortOn :: Ord b => [((a -> b), Bool)] -> [a] -> [[a]]
on groupSortOn(f, xs)
script keyBool
on |λ|(a, x)
Expand Down Expand Up @@ -5140,7 +5120,7 @@ end splitRegex

-- sqrt :: Num -> Num
on sqrt(n)
if n 0 then
if 0 <= n then
n ^ (1 / 2)
else
missing value
Expand Down Expand Up @@ -6001,7 +5981,7 @@ on tupleFromList(xs)
end if
script kv
on |λ|(a, x, i)
insertMap(a, (i as string), x)
insertDict((i as string), x, a)
end |λ|
end script
foldl(kv, {type:"Tuple" & strSuffix}, xs) & {length:lng}
Expand Down
11 changes: 5 additions & 6 deletions asPreludeDict.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions listOfFunctionNames.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ assocs :: Map k a -> [(k, a)]
base64decode :: String -> String
base64encode :: String -> String
bimap :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
bimapLR :: (a -> b) -> (c -> d) -> ֵEither ֵֵa c -> Either b d
bimapN :: (a -> b) -> (c -> d) -> TupleN -> TupleN
bind (>>=) :: Monad m => m a -> (a -> m b) -> m b
bindFn (>>=) :: (a -> b) -> (b -> a -> c) -> a -> c
bindLR (>>=) :: Either a -> (a -> Either b) -> Either b
Expand All @@ -45,7 +47,7 @@ breakOn :: String -> String -> (String, String)
breakOnAll :: String -> String -> [(String, String)]
breakOnMay :: String -> String -> Maybe (String, String)
bulleted :: String -> String -> String
cartesianProduct :: [a] -> [b] -> [(a, b)]
cartesianProduct :: [a] -> [b] -> [[a, b]]
caseOf :: [(a -> Bool, b)] -> b -> a -> b
catMaybes :: [Maybe a] -> [a]
ceiling :: Num -> Int
Expand All @@ -67,8 +69,6 @@ cons :: a -> [a] -> [a]
constant :: a -> b -> a
createDirectoryIfMissingLR :: Bool -> FilePath -> Either String FilePath
curry :: ((a, b) -> c) -> a -> b -> c
curry2 :: ((a, b) -> c) -> a -> b -> c
curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
cycle :: [a] -> Generator [a]
decodedPath :: Percent Encoded String -> FilePath
degrees :: Float x => Radians x -> Degrees x
Expand Down Expand Up @@ -169,7 +169,7 @@ getHomeDirectory :: IO FilePath
getTemporaryDirectory :: IO FilePath
group :: Eq a => [a] -> [[a]]
groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
groupSortOn :: Ord b => (a -> b) -> [a] -> [a]
groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
gt :: Ord a => a -> a -> Bool
head :: [a] -> a
headMay :: [a] -> Maybe a
Expand Down

0 comments on commit 1a86eff

Please sign in to comment.